aspose file tools*
The moose likes Testing and the fly likes testing a java application that is started via a batch file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "testing a java application that is started via a batch file" Watch "testing a java application that is started via a batch file" New topic
Author

testing a java application that is started via a batch file

Jordan Thompson
Greenhorn

Joined: Nov 09, 2009
Posts: 20
We have a GUI application that has quite a few junit tests that unit test components (both GUI as well as business) of this app.
The app is delivered as several jars and launched with a batch file (also part of the delivery.) Our jars, configuration files, 3rd party jars, etc are all delivered in a single zip file. We have had issues in the past where the delivered jar or zip file becomes broken and we don't discover this until weeks after the error occurred (most of the developers run the application from the IDE until we approach FAT time.)
In an attempt to reduce this problem, I have written another junit test that extracts the contents of the zip file and starts the application via the batch file. Unfortunately, this requires someone to observe that the app is running correctly and click the file->exit button to end this test (and allow junit to continue with the other tests in the suite.

Is there anyway that junit can access any of the class hierarchy of this application that was started by a separate batch file but is running in the jvm? This would allow the junit to look at the real-time log (that is only recorded in the log window of the app) to ensure it is started correctly and it would allow the junit to access the exit button to also shut down the application.

Thanks for any help anyone may be able to provide.

Jordan


No matter where you go - there you are
-- Buckaroo Banzai
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1779
    
    7

I don't think that's going to work using Junit.
You could just implement a flag in your application main class that starts a headless version for testing purposes. This flag would indicate to run the bootstrapping logic followed by application's shutdown routine if everything checks out. The exit code returned, either implicitly or explicitly, will indicate if all went according to plan or something went horribly wrong. That way you could use Ant to test the deployment of your application distributable generated by the buildsystem, after succesful completion of unit testing and packaging. Simply use Ant to unzip the distributable and the <exec> task with failonerror set to call the batch file and provide a flag it forwards to the java.exe invocation of the main class, which start the headless version of the application.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jordan Thompson
Greenhorn

Joined: Nov 09, 2009
Posts: 20
Jelle Klap wrote:
This flag would indicate to run the bootstrapping logic followed by application's shutdown routine if everything checks out. The exit code returned, either implicitly or explicitly, will indicate if all went according to plan or something went horribly wrong.


Works for me! great idea. Thanks very much.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: testing a java application that is started via a batch file