Software test based on the Machine Experiment 1 (triangle judgment)

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. Installing Eclemma

Two. Write Triangle and Triangletest:

1. Main code (judging triangle properties)

1  Packageexample;2 3 /**4 * Created by Ev_eraser on 2016/3/18.5  */6  Public classMyclass {7      PublicString Triangle (intAintBintc) {8         if(A + b < C | | A + c < b | | B + C <a)9             return"Nottriangle";Ten         if(A = = b && b = =c) One             return"Isosceles"; A         if(A = = B | | b = = c | | a = =c) -             return"Equilateral"; -         Else the             return"Scalene"; -     } -}

2. Testing

 Packageexample;ImportOrg.junit.After;ImportOrg.junit.Before;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;Importorg.junit.runners.Parameterized;Importjava.util.ArrayList;Importjava.util.Arrays;Importjava.util.Collection;Import Staticorg.junit.assert.*; @RunWith (parameterized.class) Public classMyclasstest {PrivateMyclass Myclass; Private intinput1; Private intInput2; Private intINPUT3; PrivateString expected;  PublicMyclasstest (intINPUT1,intInput2,intinput3,string Expected) {         This. INPUT1 =input1;  This. Input2 =Input2;  This. INPUT3 =INPUT3;  This. Expected =expected; } @Before Public voidSetUp ()throwsException {myClass=NewMyclass (); } @Parameterized. Parameters Public StaticCollection<object[]>GetData () {returnArrays.aslist (Newobject[][]{{2,2,2, "Isosceles"},            {2,2,3, "equilateral"},            {2,4,3, "Scalene"},            {2,9,2, "Nottriangle"}    }); }//@After//Public void TearDown () throws Exception {////    }@Test Public voidTesttriangle ()throwsException {assertequals ( This. Expected, Myclass.triangle (INPUT1,INPUT2,INPUT3)); }}

3. Test results

All four test cases pass, coverage 90%

Software test based on the Machine Experiment 1 (triangle judgment)

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.