• 软件测试第一次上机


    一.junit、hamcrest和eclemma的安装:

    1.junit和hamcrest在新建了junitHw1工程后在build path里通过add external jars添加junit-4.12.jar和hamcrest-all-1.3.jar。

    2.eclemma在eclipse下点击help-eclipse marketplace-find-eclemma安装。

    二.编写Triangle以及Triangletest:

    1.判断三角形:

    package example;
    
    /**
     * Created by Ev_Eraser on 2016/3/18.
     */
    public class Myclass {
        public String triangle(int a,int b,int c) {
            if(a + b < c || a + c < b || b+ c < a)
                return "notTriangle";
            if(a == b && b == c)
                return "isosceles";
            if(a == b || b == c || a == c)
                return "equilateral";
            else
                return "scalene";
        }
    }

    2.测试:

    package example;
    
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;
    
    import java.util.Arrays;
    import java.util.Collection;
    
    import static org.junit.Assert.assertEquals;
    
    @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));
        }
    }

    三.测试结果截图:

  • 相关阅读:
    poj1459(多源点网络流)
    poj 2480
    poj1850和poj1496(组合数)
    poj3252(组合数)
    hdu1452(逆元)
    因子和与因子个数
    poj 2478(欧拉函数打表)
    p3807(lucas定理)
    F-有趣的数字(组合数+逆元)
    《Java并发编程的艺术》Java并发机制的底层实现原理(二)
  • 原文地址:https://www.cnblogs.com/Theshy/p/5295171.html
Copyright © 2020-2023  润新知