Role: Junit test unit, used primarily for specialized testing procedures.
By default Junit IDEA plugin has been installed, but can not automatically generate JUnit test code. If you need to automatically generate test code, you need to install JUnitGenerator V2.0 plug-ins.
Installation: the File-> SETTINGS-> Plguins-> the Browse repositories-> input JUnit-> selected JUnit Generator V2.0 installation, installed after the restart IDEA, can be used.
If you do not want to generate junit test code, do not download JUnit Generator V2.0,
1 do not JUnit Generator V2.0
when you want to write the above function test on "@Test", which is being given, simply import junit package on the line, as shown below:
At this point, you can run the function you want to test, pay attention to the rules test methods:
- The test method must have top notes @Test
- Modification of the method must be public, not have a return value, but may throw an exception.
Adding a test example I, the Add method is defined in the MathUntil, and a test division. As shown below:
If you want to test only add, click directly in front of the test method testAdd Run button if the correct output checkmark will appear, as shown below.
If you like to say there are ways to run the entire test class, click on the Run button Text in front of the class, you get the test results of all methods, there will be the following figure in the right way, the wrong will have an "X" symbol.
To test the auto-generated code, reference https://www.cnblogs.com/ryanjan/p/8626499.html; super detail.