Junit testing with Eclipse IDE

 

Module : Software Engineering Process and Quality Management [ SEPQM ]

There was a lab session at the begin of the week. In this SEPQM lab I learnt how to handle jUnit test cases.JUnit is a unit testing framework for the Java programming language



 

In briefly this is how to do a unit test with jUnit framework.

01.) Download jUnit 5 from junit.org

02.)Go to System > Advance System settings > System variables  and add class path and junit as a system variable in your windows PC.

03.) And then open the IDE to write classes to test and to write test cases.

04.) Then write codes as usual and add the Junit library to the project and .jar file in to that Junit library. If you have no library folder as Junit you can download it via IDE's marketplace. (I used ecliipse IDE) 

05.) Then right click on the class which you are going to test and go to New > other > Junit > Junit test cases and open up a new test class and select what you are going to test.

06.) And then write test cases on the relevant test classes.Make sure to import packages which are essential to run a test class,

                  i.e: java.assert / java.junit 

 
and make sure to use the correct annotations because these are controlling test methods. i.e: @Test @After @Before

 

 07.) After writing test cases then run the test class and you can see whether the class or method is test passed or test failed.


Also we can run junit tests as a test suit. Test suits are usually used to run tests on multiple classes or methods.
 
 
 
 
Thank you for visiting my blog ! 
 
 
 
 
 

Comments

Post a Comment