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