Job Eight-triangle judging unit Test experience

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.