Test Cases
(with "()" number for false prophecy)
Serial number |
Test Input ( three sides: a,b,c) |
Test prophecy (Oracle:illegal,regular,scalene,isoceles) |
4 |
(0.6.5) |
Illegal |
5 |
(4,2,3) |
Scalence |
6 |
(4,4,4) |
Regular |
7 |
( -2,-2,-2) |
Illegal |
8 |
(3,3,5) |
Isoceles |
9 |
( -2,-2,-2) |
(Regular) |
10 |
(3,3,6) |
(isoceles) |
11 |
(a) |
(Scalene) |
Based on the forecast use case table, write the following test function:
@Test Public voidtestlsTringle4 () {Triangle T=NewTriangle (0,6,5); Assertequals (T.gettype (t),"Illegal"); } @Test Public voidtestlsTringle5 () {Triangle T=NewTriangle (4,3,2); Assertequals (T.gettype (t),"Scalene"); } @Test Public voidTestlsTringle6 () {Triangle T=NewTriangle (4,4,4); Assertequals (T.gettype (t),"Regular"); } @Test Public voidTestlsTringle7 () {Triangle T=NewTriangle ( -2,-2,-2); Assertequals (T.gettype (t),"Illegal"); } @Test Public voidTestlsTringle8 () {Triangle T=NewTriangle (3,3,5); Assertequals (T.gettype (t),"Isoceles"); } @Test Public voidTestlsTringle9 () {Triangle T=NewTriangle ( -2,-2,-2); Assertequals (T.gettype (t),"Regular"); } @Test Public voidTestlsTringle10 () {Triangle T=NewTriangle (3,3,6); Assertequals (T.gettype (t),"Isoceles"); } @Test Public voidTestlsTringle11 () {Triangle T=NewTriangle (A); Assertequals (T.gettype (t),"Scalene"); }
Run the test class and get the test result:
The results are shown (due to the function name and the test case table one by one), 4-8 runs through, the results are expected, and 9-11 results are inconsistent with expectations. Consistent with my expectations.
Experience:
When designing test cases, according to the equivalence division, how to divide into four categories: illegal triangles, general triangles, isosceles triangle, equilateral triangle. And I added 9-11 use cases to test special input data, such as (3,3,6). If the output is isosceles, it indicates that no legitimacy is judged, and assertequals (T.gettype (t), "Isoceles") in the test function produces an error.
In the Eclipse2014 version, I used its JUnit4, the test method selected Istriangle (Long,long,long) and GetType (Triangle). Note @teat before testing the method, indicating that it is a test, and that the test function must be of type void with no parameters.
In this test, I used the Assertequals method of the test class (import static org.junit.assert.*) to determine whether the actual result was consistent with the expectation.
Job Eight-triangle judging unit Test experience