软件测试Lab 1 Junit and Eclemma

时间:2025-01-11 11:04:14

首先安装eclipse

然后下载hamcrest-core-1.3.jar,下载地址:http://mvnrepository.com/artifact/org.hamcrest/hamcrest-core/1.3

下载junit-4.12.jar,下载地址:http://mvnrepository.com/artifact/junit/junit/4.12

然后安装Eclemma,打开eclipse,点击Help->Eclipse Market Place

软件测试Lab 1 Junit and Eclemma

安装重启eclipse即可,若出现软件测试Lab 1 Junit and Eclemma图标即表示安装成功。

创建一个project,格式如下

软件测试Lab 1 Junit and Eclemma

package Triangle;

public class Triangle {
public int isTriangle(int a,int b,int c){
if(a>0 && b>0 && c>0 && a+b>c && a+c>b && b+c>a){
return 1;
}
return 0;
}
public int equilateral(int a,int b,int c){
if(isTriangle(a,b,c)==1){
if(a==b && b==c){
return 1;//等边
}
}
return 0;
}
public int isosceles(int a,int b,int c){
if(isTriangle(a,b,c)==1){
if(a==b || b==c || a==b){
return 1;//等腰
}
}
return 0;
}
public int scalene(int a,int b,int c){
if(isTriangle(a,b,c)==1){
if(a==b || b==c || a==b){
return 0;//等腰
}
return 1;
}
return 0;
}
}
package Triangle;
import static org.junit.Assert.*;
import org.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith; public class TestTri {
Triangle tri=new Triangle(); @Test
public void testisTriangle(){
assertEquals(1,tri.isTriangle(1,1,1));
}
@Test
public void testequilateral(){
assertEquals(1,tri.equilateral(1,1,1));
}
@Test
public void testisosceles(){
assertEquals(1,tri.isosceles(1,1,1));
}
@Test
public void testscalene(){
assertEquals(1,tri.scalene(1,1,1));
}
}

测试结果:

软件测试Lab 1 Junit and Eclemma软件测试Lab 1 Junit and Eclemma

软件测试Lab 1 Junit and Eclemma软件测试Lab 1 Junit and Eclemma