Requirements: Write a program to determine the 3 integers of the edge around the shape is a triangle, and determine the equilateral triangle, isosceles triangle, not equilateral triangle. The Java code is written as follows:
public class Triangle {
Public String f (int A, int b, int c) {
if (a==0| | b==0| | c==0| | a+b<=c| | a+c<=b| | B+c<=a) return "is not a triangle";
else if (a==b&&a==c) return "equilateral triangle";
else if (a==b| | a==c| | B==C) return "isosceles triangle";
Else
Return "not equilateral triangle";
}
}
In the JUnit auto-generated test class, the test code is written as follows
public class Triangletest {
Triangle Tri;
@Before
public void Setup () {
Tri = new triangle ();
}
@Test
public void Testequilateral () {
String rel = TRI.F (2, 2, 2);
Assert.assertequals ("The judgment of the equilateral is problematic", rel, "equilateral triangle");
}
@Test
public void Testisosceles () {
String rel = TRI.F (3, 2, 2);
Assert.assertequals ("isosceles judgment has a problem", rel, "isosceles triangle");
}
@Test
public void Testscalene () {
String rel = TRI.F (3, 4, 5);
Assert.assertequals ("No equilateral triangle judgment problem", rel, "not equilateral triangle");
}
@Test
public void Testtri () {
String rel = TRI.F (3, 4, 8);
Assert.assertequals ("Whether there is a problem with the triangle", rel, "not a triangle");
}
}
Running the test class with the plug-in Eclemma, you can see that the test was successful and all the test cases passed:
For the problem of installing junit and Eclemma, it is simple to introduce the necessary junit packages to build path on the line, Hamcrest-all-1.3.jar,junit-4.12.jar. Installing plug-in Eclemma is even easier, with the ability to download and install directly from Eclipse.
Software test on-machine experiment