Using JUnit to test the Java triangle

Source: Internet
Author: User

Tasks:

    1. Install Junit (4.12), Hamcrest (1.3) with Eclipse
    2. Install Eclemma with Eclipse
    3. Write a Java program for the Triangle problem and test, with Junit.

A link to the code for the triangle problem is as follows:

Https://github.com/Cartisia/triangle

Sections are as follows:

1. Install and use JUnit, Hamcrest and Eclemma.

1) Download junit-4.12, hamcrest-all-1.3 jar package Separately, can be stored in MyEclipse folder.

2) Use JUnit and hamcrest to test classes in Java

Under Java Project, create a source folder other than SRC, named Test, create a package under test, the package name is the same as the package name of the class under test in SRC, and then create the test class.

Add JUnit and Hamcrest, right-click the project->build path->add External jars, and then add the package under the appropriate path. The class that is required to import the test in the test class when it is used.

3) Install Eclemma

Click Help->eclipse marketplace->find in MyEclipse, enter Eclemma in the search box, select Install to complete the installation, restart Myelipse, right-click Project Coverage as to view Code invocation status.

Select Windows->show View->other->java->coverage to see the coverage of code execution, which is to view unit test coverage, and you can see the execution coverage of each class and the entire project code.

2. The result of the execution of the Triangle test case and the corresponding coverage

Using JUnit to test the Java triangle

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.