Junit test unit using the IDEA

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/hyy_blue/article/details/93163771

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:
Here Insert Picture Description
At this point, you can run the function you want to test, pay attention to the rules test methods:

  1. The test method must have top notes @Test
  2. 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.

Here Insert Picture Description

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.
Here Insert Picture Description

To test the auto-generated code, reference https://www.cnblogs.com/ryanjan/p/8626499.html; super detail.

Guess you like

Origin blog.csdn.net/hyy_blue/article/details/93163771