Unit Test Exercises

Source: Internet
Author: User

1. To judge Java code for the triangle given in Appendix 1, Apply equivalence class partitioning method to design test cases and list the design test cases in tabular form.

Error prediction in "()" in Test prophecy

Serial number

Test input: Three edges (a,b,c) Test Prophecy (Oracle:illegal,regular,scalene,isoceles)
1 (4,3,2) Scalene
2 (0,5,5) Illegal
3 (4,4,4) Regular
4 ( -1,-1,-1) Illegal
5 (3,4,5) (illegal)
6 (a) Illegal
7 ( -1,-1,-1) (Regular)
8 (4,4,5) Isoceles

2. Simulate the JUnit test code with the triangle given in Appendix 2, design the unit test script, and test the test case that the "1" design obtains.

Package Com.cvicse.test.junit;importStaticorg.junit.assert.*; import Org.junit.after;import org.junit.before;import org.junit.Test; Public classtriangletest {@Before Public voidsetUp () throws Exception {} @After Public voidTearDown () throws Exception {} @Test Public voidTest () {fail ("Not yet implemented"); } @Test Public voidTestlsTringle1 () {Triangle T=NewTriangle (4,3,2); Assertequals (T.gettype (t),"Scalene"); } @Test Public voidTestlsTringle2 () {Triangle T=NewTriangle (0,5,5); Assertequals (T.gettype (t),"illegal"); } @Test Public voidTestlsTringle3 () {Triangle T=NewTriangle (4,4,4); Assertequals (T.gettype (t),"Regular"); } @Test Public voidtestlsTringle4 () {Triangle T=NewTriangle (-1,-1,-1); Assertequals (T.gettype (t),"illegal"); } @Test Public voidtestlsTringle5 () {Triangle T=NewTriangle (3,4,5); Assertequals (T.gettype (t),"illegal"); } @Test Public voidTestlsTringle6 () {Triangle T=NewTriangle (1,2,3); Assertequals (T.gettype (t),"illegal"); } @Test Public voidTestlsTringle7 () {Triangle T=NewTriangle (-1,-1,-1); Assertequals (T.gettype (t),"Regular"); } @Test Public voidTestlsTringle8 () {Triangle T=NewTriangle (4,4,5); Assertequals (T.gettype (t),"Isoceles"); }}

3. Test result run diagram:

The result is the same as I imagined.

My GitHub Link: https://github.com/MocQiQi/homework/blob/master/job 8.txt

4. Experience: Because the class did not listen carefully, leading to the test of the link to touch the mind, even looking at other people's blog is also confused, in the re-study finally succeeded. I'm using JUnit 4. And under the test case, according to the equivalence division can be divided into four categories: equilateral triangle, non-equilateral triangle, isosceles triangle and general triangles. Note the @test before testing.

Unit Test Exercises

Related Article

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.