软件测试学习(3) 第一次上机实验

实验要求:

  1. Install Junit(4.12), Hamcrest(1.3) with Eclipse
  2. Install Eclemma with Eclipse
  3. Write a java program for the triangle problem and test the program with Junit.

  a) Description of triangle problem:

  Function triangle takes three integers a,b,c which are length of triangle sides; calculates whether the triangle is equilateral, isosceles, or scalene. 

实验代码:

Triangle类:

package ST;

public class Triangle {    
    public String judge(double a, double  b, double  c)
    {
        if(a+b>c&&b+c>a&&a+c>b)
        {
            if(a==b||b==c||c==a)
            {    
                if(a==b&&b==c)
                    return "equilateral";
                else return "isosceles";
            }
            else return "scalene";
        }
        else return "it is not a triangle";        
    }
}

测试类:

package ST;

import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert .*;

public class TriangleTest {
    private Triangle triangle;
    
    @Before
    public void setUp() throws Exception {
        triangle = new Triangle();
    }
    
    @Test
    public void test()
    {
        assertEquals("isosceles", triangle.judge(4,4,5));
        assertEquals("it is not a triangle", triangle.judge(1,1,5));
        assertEquals("equilateral", triangle.judge(4,4,4));
        assertEquals("scalene", triangle.judge(3,4,5));
    }
    
}
原文地址:https://www.cnblogs.com/tjuwx/p/5295676.html