Today, I tried to test the project using Juint and Eclemma in the Machine class.
The first is the installation of these two tools, juint is easier, just need to bring the jar package into the project, and Eclemma need to choose to install new software in Eclipse to install.
After installation, is to complete the programming of the test project, this time the testing code is a method to detect the shape of the triangle. My code is as follows:
PackageCom.triangleproblem;Importjunit.framework.Test; Public classTriangle { PublicTriangle () {} Public BooleanTestthreesideamount (intSideone,intSidetwo,intSidethree) { BooleanIsright =false; if((Sideone + sidetwo >Sidethree)) {Isright=true; } returnIsright; } Public BooleanTestistriangle (intSideone,intSidetwo,intSidethree) { BooleanIstriangle =false; if(Sideone > 0 && sidetwo > 0 && sidethree > 0){ if(Testthreesideamount (Sideone, Sidetwo, Sidethree)) {if(Testthreesideamount (Sideone, Sidethree, Sidetwo)) {if(Testthreesideamount (Sidetwo, Sidethree, Sideone)) {Istriangle=true; } } } } returnIstriangle; } Public BooleanTestsideequal (intSideone,intsidetwo) { Booleanequals =false; if(Sideone = =sidetwo) {equals=true; } returnequals; } PublicString Test (intSideone,intSidetwo,intSidethree) {String result; BooleanIstriangle = This. Testistriangle (Sideone,sidetwo,sidethree); if(istriangle) {BooleanAB = This. Testsideequal (Sideone, sidetwo); BooleanAC = This. Testsideequal (Sideone, Sidethree); BooleanBC = This. Testsideequal (Sidetwo, Sidethree); if(AB && ac &&BC) {Result= "equilateral"; }Else if(! (ab | | ac | |BC)) {Result= "Scalene"; }Else{result= "Isosceles"; } }Else{result= "Not a Triangle"; } returnresult; } }
In this code, there are mainly Testthreesideamount (), Testistriangle (), testsideequal () and test () four methods, their function is to test the sum of the first two parameters is greater than the third parameter, Test whether the three digits of the input can form a triangle, test whether two parameters are equal, and determine the shape of the triangle.
To test these methods, I write the code for four test cases, test each method separately, and in each piece of code I have the appropriate test cases for all possible situations, so that you can achieve 100% coverage when you test with Eclemma.
The final test results are as follows:
The results show that there are 28 test cases without errors, and the coverage of target code Triangle.java reaches 100%, so the test is completed.
Liam's Software Testing Learning Journey (iii): Juint use