軟體測試基礎上機實驗1(三角形的判斷)

來源:互聯網
上載者:User

標籤:

一.junit、hamcrest和eclemma的安裝:

1.junit和hamcrest在建立了junitHw1工程後在build path裡通過add external jars添加junit-4.12.jar和hamcrest-all-1.3.jar。

2.安裝eclemma

二.編寫Triangle以及Triangletest:

 1.主要代碼(判斷三角形性質)

 1 package example; 2  3 /** 4  * Created by Ev_Eraser on 2016/3/18. 5  */ 6 public class Myclass { 7     public String triangle(int a,int b,int c) { 8         if(a + b < c || a + c < b || b+ c < a) 9             return "notTriangle";10         if(a == b && b == c)11             return "isosceles";12         if(a == b || b == c || a == c)13             return "equilateral";14         else15             return "scalene";16     }17 }

2.測試

package example;import org.junit.After;import org.junit.Before;import org.junit.Test;import org.junit.runner.RunWith;import org.junit.runners.Parameterized;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import static org.junit.Assert.*;@RunWith(Parameterized.class)public class MyclassTest {    private Myclass myClass;    private int input1;    private int input2;    private int input3;    private String expected;    public MyclassTest(int input1, int input2,int input3,String expected){        this.input1 = input1;        this.input2 = input2;        this.input3 = input3;        this.expected = expected;    }    @Before    public void setUp() throws Exception {        myClass = new Myclass();    }@Parameterized.Parameters    public static Collection<Object[]> getData(){    return Arrays.asList(new Object[][]{            {2,2,2,"isosceles"},            {2,2,3,"equilateral"},            {2,4,3,"scalene"},            {2,9,2,"notTriangle"}    });    }//    @After//    public void tearDown() throws Exception {////    }    @Test    public void testTriangle() throws Exception {        assertEquals(this.expected, myClass.triangle(input1,input2,input3));    }}

3.測試結果

 

 

四個測試案例都通過,覆蓋率90%

軟體測試基礎上機實驗1(三角形的判斷)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.