Exercise: Using JUnit
Note:- Maven Must be configured to follow this tutorial
1. First create a Maven Project Right Click on project Explorer -> New -> Others
2. Select ->Maven Click-> Maven Project|On the next screen Click -> Next Button
3. Choose Appropriate GrpuoId/ ArtifactId from the list | Click -> Next
For the sample projcet I choose maven-archetype-quickstart, choose maven-archetype-webapp
4. Fill the textboxes with appropriate names | Click -> Finish
5. The newly created Project appears on the Project Explorer window
6. Right Click the project -> Run As -> Maven package | Then project must build Successfully
7. Explore the project you find App.java and AppTest.java file
8. Open App.java file and write following Code
code sample
code sample
private int val1,val2;
public int add(int i, int j)
{
val1 = i;
val2 = j;
int result = i+j;
return result;
}
9. Open AppTest.java file and write following Code
code sample public void testAdd()
{
App ap =new App();
int actulaResult= ap.add(5, 5);
assertTrue(actulaResult == 10);
}
10. Right Click AppTest.java file | Click -> Run As | Click -> JUnit Test
11. Add testCases and re-run the class for further testing.
1 comment:
This is extremely great; it truly clarified TDD for me and why TDD is superior in terms of bdd vs tdd vs ddd.
Post a Comment