Liam's Software Testing Learning Journey (iii): Juint use

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.