Java uses JUnit tools for unit Testing

Source: Internet
Author: User

Directory

1. Definition of class:

Use of 2.Junit tools:

3. Unit test the class and view the results:

4. Record the time of each stage

5. Record the process on your personal blog (GitHub address)

1. Class definition: A class is a generic term for the same thing, a class is a carrier of the properties and behavior of the encapsulated object, and conversely, a class of entities with the same properties and behavior is called classes.

Use of 2.Junit tools:

The first step

First create a new project called Junit_test, we write a calculator class, this is a simple implementation of the subtraction, square, root of the calculator class, and then the function of the monomer test.

The second step is to introduce the JUNIT4 Unit test package into this project: Right-click on the item, click "Properties",

In the pop-up Properties window, first select "Java Build Path" on the leftand then the "Libraries" tab to the right. Then click "Add Library ..." On the far right. "button, as shown in :

then, in the New Popup dialog box, selectJUNIT4 and click OK, as shown, The JUnit4 software package is included in our project.

The third step is to generate the JUnit Test framework: The package in Eclipse Explorer , right-click on the pop-up menu and select "New à JUnit Test case ". As shown in the following:

After clicking "Next", the system will automatically list the methods contained in your class and choose the method you want to test. In this example, we only test the "add, subtract, multiply, divide" four methods.

The system then automatically generates a new class calculatortest, which contains some empty test cases. You only need to make these test cases slightly modified to use.

Fourth step, run the test code: After the above code has been modified, we Right-click on the Calculatortest class and selectRun as à JUnit Test "To run our tests, as shown in:

The results of the operation are as follows:

4. Record the time of each stage

Program Plan 20

Programming 30

Program code 20

Program Test 30

GitHub Address Https://github.com/haitianjingyu/hai1

Java uses JUnit tools for unit Testing

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.