Thursday, 2 May 2013

Running Junit tests with jmockit in eclipse

Running Junit tests with jmockit in eclipse


Junit is popular unit testing framework and jmockit is used to mock the objects.

eclipse is my favorite IDE (integrated development environment) software tool that provides writing,debug, deploy code and exusting test cases.

eclipse provides different plugins like junit and maven plugins

After installing junit and maven plugins to eclipse, we have to do following changes

junit and jmockit jars should be in project classpath
Add test directoroy in your project to eclipse project build path, eclipse compiles succesfully('Use as source folder').

Please see below screenshot for adding java build path in eclipse



Next step is to add the jmockit configuration to project jvm arguments
To execute the test class, do right click and select Run dialog (Run As --> Open Run Dialog)
and select Junit to execute tests
keep default settings in dialog and create a juni test for the class and click on arguments tab.
Add to vm arguments: '-javaagent:pathtothisjar/jmockit.jar' (if using Maven, use '-javaagent:${env_var:HOME}/.m2/repository/jmockit/jmockit/1.0/jmockit-1.0.jar')
Click 'Apply' or click 'Run'




Please share this post if you like this post.



0 comments:

Post a Comment