Unit Tests for Java code

Source: Internet
Author: User


1. First create a new project called Junittest, I write a calculator class, this is a simple implementation of the subtraction, square, root of the calculator class, and then the functions of the Unit test;

2. In the second step, the JUNIT4 unit test package is introduced into this project: Right-click on the item, click "Properties", in the pop-up Properties window, first select "Java Build Path" on the left, then select "Library" tab on the right, then click "Add Library ..." button on the far right. Then select JUNIT4 and click OK in the new Popup dialog box.

3. Generate the JUnit test framework: In Eclipse's Package Explorer, right-click on the pop-up menu and select "Java test Case";

4. On the generated page, select ' New JUNIT4 test ', ' SetUp ' tab, click "Next", the system will automatically list the methods contained in your class, select "Add, subtract, multiply, divide" four methods to test, then the system will automatically generate a new class Calculatortest , which contains some empty test cases.

5. Finally, modify these test cases slightly, then right-click on the Calculatortest class, select "Run as" and select "1 JUnit Test" to run, the test results indicate "run count 4, ignore 1, error 0,

Number of failures 1 ", running results

Unit Tests for Java code

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.