Steps:
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