gen-test-plugin
In our daily code writing process, we often need to write test cases for the code.
With the increasing demand for code quality, many companies are beginning to use test coverage of code as a measure of QA.
This framework can generate junit test cases for all code in one click, saving you valuable time in your life.
features
-
Support to generate junit4/junit5
-
Support jdk7
-
Supports custom template generation
gen-test
Used to generate Junit4/Junit5 unit tests.
The introduction of
<plugin>
<groupId>com.github.houbb</groupId>
<artifactId>gen-test-plugin</artifactId>
<version>0.0.1</version>
</plugin>
Copy the code
Attributes that
attribute | instructions | The default value | type | note |
---|---|---|---|---|
isOverwriteWhenExists | Whether to overwrite the test file if it already exists | false | string | By default, no overwrite is performed |
encoding | Project code | utf-8 | string | |
includes | Include file re | **\/*.java |
string | Default is all Java files |
excludes | Excluded file regularization | string | By default, exclusion is not performed | |
junitVersion | Junit version | 4 | string | The default for the takeup |
run
Command line execution
MVN com. Making. Houbb: gen - test - the plugin: 0.0.1: gen - testCopy the code
Directly run the gen-test plug-in to generate the corresponding test class in the project test directory.
The effect
For example, projects have the following categories:
public class HelloTestDemo {
public static String hello(a) {
return "hello"; }}Copy the code
Generate the corresponding test file:
package com.github.houbb.gen.maven.plugin.util;
import org.junit.Test;
/**
* HelloTestDemo Tester.
*
* @author houbinbin
* @since Tue Nov 14 16:01:53 CST 2017
* @version1.0 * /
public class HelloTestDemoTest {
/** * * Method: hello() */
@Test
public void helloTest(a) throws Exception {}}Copy the code
Junit5 template
If you want to customize it, you can create the junitTest5.ftl file in the Maven project Resources folder and modify it based on the following.
Junit 4 template
The above file generation is generated from the following template (Freemarker syntax)
If you want to customize it, you can create the junitTest4.ftl file in the Maven project Resources folder and modify it based on the following.
- entry
Information about the entity class to be generated.
The ${entry. PackageName} package name
The ${entry. The className} class name
Entry.methodlist gets a list of all non-private/non-main () methods. The list of private methods is not provided at the moment, but can be added later.
- today
Current date. Consider adding formatting configurations later.
- method
Method properties
${method.signature} Specifies the signature of the method
${method.name} Specifies the name of the method
${method.comment
${method.sourcecode} the code inside the method
package ${entry.packageName}; import org.junit.Test; /** * ${entry. ClassName} Tester. ** @author houbinbin * @since ${today} * @version 1.0 */ public class ${entry.className}Test { <#if entry.methodList?? > <#list entry.methodList as method> /** * * Method: ${method.signature} */ @Test public void ${method.name}Test() throws Exception { } </#list> <#else> </#if> }Copy the code
Develop reading
Idoc – Automatically generates code documentation
Data-factory – Automatically generates test objects based on class
The source code to learn
Gen-test-plugin is open source, you can click on the link to learn the source code.
If there is help for you, you can give a star to support the author.
The public,
More technical articles, life fun, all in “old horse roar west wind”.