Judging triangles and using junit tests

Source: Internet
Author: User

I. the process of installing Junit,hamcrest and eclemma

1. Download Junit 's jar Package and hamcrest, which is currently available in version JUnit 4.12, which can be downloaded from www.junit.org .

2.OpenEclipse, when you want to useJunitof theProjectname, clickProperties--java Build Path-libraries, clickAdd External JARs, putJuniton the package point. 1as shown, clickAdd External JARs, select the appropriateJunitpackage.

Figure 1 installing the junit Package

3. Open eclipse, select help->eclipse marketplace-> search eclemma , Install . restarting the Eclipse Discovery toolbar appears with a Coverage icon stating that the installation was successful. as shown in 2.

Figure 2 the Coverage icon appears on the toolbar

Ii. Write a small program and write a test program with JUnit and view coverage

1. Title:

Function triangle: There are 3 integers of number a,b,c, respectively, the edge length of the triangle , judging the triangle is equilateral triangle, isosceles triangle or non-equilateral non-isosceles triangle.

2. Small program written: only the method of discrimination is written, the program is not complete, and the default a,b,C is the integer length of the triangle, this does not discriminate.

3 shown: The figure is Eclemma after viewing the code, the results are all green and the code is executed. (The yellow Description code part executes to, the red instruction code is not executed to)

Figure 3 Triangle Program

3. Write the unit test: write the test case according to the program and let it overwrite each statement. as shown in 4.

Figure 4 junit test program

4. Eclemma Detection coverage: Select window->show view->other->java->coverage to see the coverage of code execution. as shown in 5.

Figure 5 Eclemma detection Coverage

Judging triangles and using junit tests

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.