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 Suxin, we write a class , this is a simple implementation of the addition 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 left, then go to the top right to select " Libraries"tag, then on the far right click on the"Add Library ... "button, as shown in :

Then, in the New Popup dialog box, selectjunit4junit4
    third step, generate junit test framework: in eclipse package Explorer< Span style= "font-size:large;" Right click on the pop-up menu and select "new à junit Test case ". As shown:

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 "plus" method.

The system then automatically generates a new class classtest, which contains some empty test cases. I just need to make these test cases a little bit of modification to use.

The results of the operation are as follows:

4. Record the time of each stage

Program Schedule 15 minutes

Programming 20 minutes

Program code 10 minutes

Program Test 30 minutes

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.