First, install Junit,hamcrest and Eclemma
Both JUnit and Harmcrest are built into the project as a jar package. The process of installing the jar package is simple, as long as the new project is imported or imported directly into the project. As shown in the following:
You can add additional jar packages directly to your project, or you can add jar package paths to classpath.
Eclemma can be installed through Eclipse's market, search for Eclemma, and agree to reboot after installation.
Ii. contents of the experiment
Experimental complete code uploaded to GitHub: Software Test Experiment one @ Yang Shepherd
The experimental procedure is a simple function for judging the triangle type, and the input parameter is three int, which represents the three edges of the triangle. The return value is int, 0 is equilateral triangle, 1 is isosceles triangle, 2 is not equilateral triangle, 3 is the default, that is, the code is not entered, and the program may have an error.
Using JUnit for a simple test, you can use the Eclipse shortcut, right-click Project->new->junit test case, test the above functions, set before and after actions, use Runwith, Build a parameter list to test the function, and test it as follows:
The use case parameter list is as follows:
Eclemma coverage statistics are as follows:
Third, the matters needing attention
In order to avoid source code and better separation test code, the test code and source code should be placed in different code source folders.
At the same time, the program should not only solve the problem of the correctness of the running result, but also include the test of the legality of the parameters. For example, the triangle three edges must all be positive integers, and the decimal input is not accepted by the function unless the transformation is used. For the input of a non-positive integer, it is necessary to make a judgment, if there is an input parameter is a non-positive integer, then the function returns 1 value, expressed as the input is illegal. After modifying a function, you can add the following test cases:
The test results are as follows:
Iv. Summary
The Java test methodology is very well developed and has a lot of tools to test. In the process of testing, we should take into account as many situations as possible to meet the requirements of the procedure and to request the completeness of the procedure.
Test one of software testing--how to use Junit,hamcrest and Eclemma for simple software testing