Software Test Experiment One

Source: Internet
Author: User

The 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.

Second, the preparation of triangle and TestTriangle1.

1.triangle-Judging triangle type

public class Triangle {int[] data;  Triangle () {data = new int[3], public void SetData (int[] number) {for (int i = 0;i < data.length;i++) {Data[i] = Numbe R[i]; }} public     String Checktriangle () {for     (int i = 0;i < data.length;i++) {      if (data[i]<=0)      return " Illegal ";     }     if (data[0]+data[1]<=data[2]| | data[0]+data[2]<=data[1]| | Data[1]+data[2]<=data[0]) {     return "not triangle";     }     else if (data[0]==data[1]&&data[0]==data[2]) {     return "equilateral";     }     else if (data[0]==data[1]| | data[0]==data[2]| | Data[1]==data[2]) {     return "isosceles";     }     else     return "Scalene";     }}

2.TriangleTest

Import static Org.junit.assert.*;import Java.util.arrays;import Java.util.collection;import Org.junit.Test;import Org.junit.runner.runwith;import Org.junit.runners.parameterized;import org.junit.runners.Parameterized.Parameters; @RunWith (parameterized.class) public class triangletest{@ Parameterspublic static Collection Preparedata () {return arrays.aslist (new object[][]{{1,3,5, "not triangle"},{1,2,-3, "Illegal"},{3,4,5, "Scalene"},{2,2,2, "equilateral"},{2,3,3, "Isosceles"}}); Public triangletest (int param1,int param2,int param3,string result) {this.param1 = Param1;this.param2 = param2; THIS.PARAM3 = Param3;this.result = result;} @Testpublic void Test () {Triangle.setdata (new int[]{param1,param2,param3}); Assertequals (result, Triangle.checktriangle ());} private int param1,param2,param3;private String result;private static Triangle Triangle = new Triangle ();}

Third, test results

Software Test Experiment One

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.