This is the 11th day of my participation in Gwen Challenge

Every time to Test the method of a class, we manually create a Test Test class and then write a method with the same name. Every time, this will be very tedious. IDEA development tool provides a plug-in JUnitGenerator that automatically generates Test classes.

Install the plug-in JUnitGenerator

Open the IDEA and search for JUnitGenerator by clicking Preferences–> Plugins –>Marketplace

Check the plug-in for use after it is installed (it is already installed by default)

The plug-in configuration

After a successful installation, you can find the configuration for JUnit to automatically generate test classes, as shown below:

Configuration parameters:

  • Medhod Generation Style: method Generation Style (ParamName indicates the method parameter name is the original test method parameter name)
  • Output Path: Configures the address generated by the test class
  • Default Template: Junit test class Template, selected based on the Jar package

I’m using here

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
Copy the code

Here is a comparison of code templates for different versions of the Junit test class:

How to use

Open the code you want to generate the test class, right-click anywhere, as shown:Select the test package version used by the project, the class name, the method to be tested, and so onThis is the effect of generating the final test classAs for the content inside the method body, we need to supplement it by ourselves. In this way, we can quickly generate test methods for corresponding target classes and clearly know which methods do not have corresponding test codes, which is convenient for the subsequent supplement and improvement of test coverage.

👍 ❤️ Don’t get lost

The article continues to update every week, you can search wechat “ten minutes to learn programming” the first time to read and urge more, if this article is not bad, feel something if you support and recognition, is the biggest power of my creation, we will see the next article!