st lab1: junit and eclemma

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了st lab1: junit and eclemma相关的知识,希望对你有一定的参考价值。

1.install junit and eclemma

在网上搜素并下载junit-4.12.jar 和 hamcrest-core-1.3.jar 两个jar包,在项目里创建一个lib文件夹将jar包放进去,再右键选择这两个jar包,选择Build Path->add to build path 即可。

安装eclemma:

点击eclipse的help,选择eclipse marketplace, 在find框里搜索eclemma并按照指示安装即可。

2.lab code

package test1;

import java.util.Arrays;

public class triangle {
    private static String result = "";
    private static int[] length = new int[3];
    
    public void clearArray(){
        for(int i=0;i<3;i++){
            length[i] = 0;
        }
    }
    
    public static void getIntegers(int a,int b,int c){
        length[0] = a;
        length[1] = b;
        length[2] = c;
        Arrays.sort(length);
    }
    
    public static void judgeIllegal(){
        if(length[0] + length[1] <= length[2]){
            result = "illegal";
        }
    }
    
    public static void judgeEquilateral(){
        if(length[0] == length[1] && length[1] == length[2]){
                result = "equilateral";
            }
    }
    
    public static void judgeiossceles(){    
        if(length[0] == length[1] || length[1] == length[2]){
                result = "isosceles";
            }
    }
    
    public static void judgeScalene(){
        if(length[0] != length[1] && length[1] != length[2]){
            result = "scalene";
        }
    }
    
    public static String getResult(){
        return result;
    }
    
}
package test1;

import static org.junit.Assert.*;

import org.junit.Test;

public class triangleTest {

	@Test
	public void testJudgeIllegal() {
		triangle.getIntegers(3, 3, 7);
		triangle.judgeIllegal();
		assertEquals("illegal", triangle.getResult());
	}

	@Test
	public void testJudgeEquilateral() {
		triangle.getIntegers(3, 3, 3);
		triangle.judgeEquilateral();
		assertEquals("equilateral", triangle.getResult());
	}

	@Test
	public void testJudgeIossceles() {
		triangle.getIntegers(3, 3, 4);
		triangle.judgeIossceles();
		assertEquals("isosceles", triangle.getResult());
	}

	@Test
	public void testJudgeScalene() {
		triangle.getIntegers(3, 4, 5);
		triangle.judgeScalene();
		assertEquals("scalene", triangle.getResult());
	}

}

  

以上是关于st lab1: junit and eclemma的主要内容,如果未能解决你的问题,请参考以下文章

st lab1: junit and eclemma

#ST# Lab1 for ST

ST lab1——Junit和覆盖测试的初探

Lab1 - Junit and Eclemma

ST:Lab1实验报告(测试判断三角形边长)

Lab1 Junit安装使用