Tasks:
- Install Junit (4.12), Hamcrest (1.3) with Eclipse
- Install Eclemma with Eclipse
- Write a Java program for the Triangle problem and test, with Junit.
A link to the code for the triangle problem is as follows:
Https://github.com/Cartisia/triangle
Sections are as follows:
1. Install and use JUnit, Hamcrest and Eclemma.
1) Download junit-4.12, hamcrest-all-1.3 jar package Separately, can be stored in MyEclipse folder.
2) Use JUnit and hamcrest to test classes in Java
Under Java Project, create a source folder other than SRC, named Test, create a package under test, the package name is the same as the package name of the class under test in SRC, and then create the test class.
Add JUnit and Hamcrest, right-click the project->build path->add External jars, and then add the package under the appropriate path. The class that is required to import the test in the test class when it is used.
3) Install Eclemma
Click Help->eclipse marketplace->find in MyEclipse, enter Eclemma in the search box, select Install to complete the installation, restart Myelipse, right-click Project Coverage as to view Code invocation status.
Select Windows->show View->other->java->coverage to see the coverage of code execution, which is to view unit test coverage, and you can see the execution coverage of each class and the entire project code.
2. The result of the execution of the Triangle test case and the corresponding coverage
Using JUnit to test the Java triangle