How to Use Jemmy with JUnit in NetBeans IDE
Join the DZone community and get the full member experience.
Join For Freewe are always constantly looking to improve and refine our testing. currently we are looking into improving our tests for forms in our pdf viewer.
for the gui testing we are using jemmy , a library that comes with the netbeans ide and is very useful for testing swing applications. netbeans also comes with junit bundled in for unit testing that we also make use of. if you are writing a module and want to use jemmy this is a good place to start. however if you want to use jemmy with a project as opposed to a module you will need to remember to add it to the classpath.
so we wanted to have our jemmy tests run as part of our unit testing but there wasn't much in the way of documentation on how to do this.
upon investigation it is actually very easy to get them working together. what you need to do is simply write junit tests that utilize jemmy so for example:
@test public void junittest() { jframeoperator mainframe = new jframeoperator(); jtextfieldoperator textfield = new jtextfieldoperator(mainframe, "textin"); int x = 10; assertequals(x, textfield.getlocationonscreen().x); }
adding the @test annotation and making use of junit's assertequals() and fail() if needed.
and that's pretty much it!
one thing worth mentioning is that when reading/writing text files for loading test data it's important to make sure you explicitly set the encoding. as i found that when running jemmy as a standalone test, not using the test option in netbeans and not as part of a junit test, it used a different default encoding to when using the test option and running it as part of our unit testing.
what methods do you use to improve your testing?Opinions expressed by DZone contributors are their own.
Comments