Software testing first time on the machine Hu Xiao

Source: Internet
Author: User

I. Installation of JUnit, Hamcrest, and Eclemma:

1.junit and Hamcrest add Junit-4.12.jar and Hamcrest-all-1.3.jar in build path by adding external jars after creating a new JUNITHW1 project.

2.eclemma Click Help-eclipse marketplace-find-eclemma Install under Eclipse.

Two. Write Triangle and Triangletest:

1. Judging triangles:

Package JUnit; Public classTriangle {Private Static intEquilateral =1;Private Static intIsosceles =2;Private Static intScalene =3;Private Static intError =4; Public intgetequilateral () {returnequilateral; } Public intGetisosceles () {returnisosceles; } Public intGetscalene () {returnScalene; } Public intGetError () {returnerror; } Public intTypeintAintBintc) {    if(a<=0|| b<=0|| c<=0)    {        returnerror; }    Else if(a+b<c| | a+c<b| | b+c<a) {returnerror; }    Else if(a!=b&&b!=c&&a!=c) {returnScalene; }    Else if(a==b&&b==c) {returnequilateral; }    Else if(a==b| | a==c| | b==c) {returnisosceles; }    return 0;}}

2. Test:

Package Junit;import Org.junit.test;importStaticorg.junit.assert.*; Public classTriangletest {PrivateTriangle triangle =Newtriangle (); @Test Public voidTestnottriangel () {assertequals (Triangle.geterror (), Triangle.type (0,2,3)); } @Test Public voidTestscalene () {assertequals (Triangle.getscalene (), Triangle.type (3,2,4)); } @Test Public voidTestisosceles () {assertequals (Triangle.getisosceles (), Triangle.type (3,2,3)); } @Test Public voidtestequilateral () {assertequals (Triangle.getequilateral (), Triangle.type (3,3,3)); }}

Three. Test results:

All four test cases pass, coverage 94.9%

Software testing first time on the machine Hu Xiao

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.