Skip to content

Generating Unit-Test-Stubs for Java using Annotation Processing

License

Notifications You must be signed in to change notification settings

sneufeind/test-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test-generator

Generating Unit-Test-Stubs for Java using Annotation Processing

Intention

The idea is to improve unit test coverage without implementing to much boilerplate code. The delevoper doesn't care anymore, whether to write a unit test or not. Now he explicitly decides against writing an unit test, if it doesn't make sense.

Getting started with Maven

  1. Add the annotation-processor to your maven-compiler-plugin in your pom.xml.
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <annotationProcessorPaths>
          <path>
            <groupId>de.nms.test</groupId>
            <artifactId>annotation-processor</artifactId>
            <version>${latest.annotation-processor.version}</version>
          </path>
        </annotationProcessorPaths>
        <annotationProcessors>
          <proc>de.nms.test.apt.processor.TestingAnnotationProcessor</proc>
        </annotationProcessors>
      </configuration>
    </plugin>
  </plugins>
</build>
  1. Add the annotations-dependency to your project:
<dependencies>
  <dependency>
    <groupId>de.nms.test</groupId>
    <artifactId>annotations</artifactId>
  </dependency>
</dependencies>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>de.nms.test</groupId>
      <artifactId>annotations</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>
  1. Create a java class annotated with @GenerateTestStub. If you're looking for examples, please have closer look to samples.
  2. There will be an unit test class automatically generate for every public and non-abstract method implemented in that class.
shell> mvn clean compile
  1. To avoid generating a test for a single method you'll be able to add the @GenerateNoTestStub to the method itself.

About

Generating Unit-Test-Stubs for Java using Annotation Processing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages