实验名称
Junit and Eclemma
实验目标
Install Junit and write a Java program with it.
实验内容
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.
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.
实验步骤
1.下载安装Junit、hamcrest and eclemma
2.Write a java program for the triangle problem and test the program with Junit.
code:
1 package lab1; 2 3 public class Triangle { 4 public static String triangleshape(int a,int b, int c){ 5 if(a == b && a == c && b == c){ 6 return "equilateral"; 7 } 8 else if(a == b || a == c || b == c){ 9 return "isosceles";10 }11 else{12 return "scalene";13 } 14 } 15 }
1 package lab1; 2 3 import static org.junit.Assert.*; 4 import java.util.Arrays; 5 import java.util.Collection; 6 import org.junit.Test; 7 import org.junit.runner.RunWith; 8 import org.junit.runners.Parameterized; 9 import org.junit.runners.Parameterized.Parameters;10 11 @RunWith(Parameterized.class)12 public class Testing {13 14 private int a;15 private int b;16 private int c;17 private String expected;18 private String result = null;19 20 public Testing(int a,int b, int c, String expected){21 this.a = a;22 this.b = b;23 this.c = c;24 this.expected= expected; 25 }26 27 @Parameters28 public static Collection
3、run