I. the process of installing Junit,hamcrest and eclemma
1. Download Junit 's jar Package and hamcrest, which is currently available in version JUnit 4.12, which can be downloaded from www.junit.org .
2.OpenEclipse, when you want to useJunitof theProjectname, clickProperties--java Build Path-libraries, clickAdd External JARs, putJuniton the package point. 1as shown, clickAdd External JARs, select the appropriateJunitpackage.
Figure 1 installing the junit Package
3. Open eclipse, select help->eclipse marketplace-> search eclemma , Install . restarting the Eclipse Discovery toolbar appears with a Coverage icon stating that the installation was successful. as shown in 2.
Figure 2 the Coverage icon appears on the toolbar
Ii. Write a small program and write a test program with JUnit and view coverage
1. Title:
Function triangle: There are 3 integers of number a,b,c, respectively, the edge length of the triangle , judging the triangle is equilateral triangle, isosceles triangle or non-equilateral non-isosceles triangle.
2. Small program written: only the method of discrimination is written, the program is not complete, and the default a,b,C is the integer length of the triangle, this does not discriminate.
3 shown: The figure is Eclemma after viewing the code, the results are all green and the code is executed. (The yellow Description code part executes to, the red instruction code is not executed to)
Figure 3 Triangle Program
3. Write the unit test: write the test case according to the program and let it overwrite each statement. as shown in 4.
Figure 4 junit test program
4. Eclemma Detection coverage: Select window->show view->other->java->coverage to see the coverage of code execution. as shown in 5.
Figure 5 Eclemma detection Coverage
Judging triangles and using junit tests