Test Pojos Maven Plugin

Unit test pojos

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

org.honton.chas
ArtifactId

ArtifactId

testpojo-maven-plugin
Last Version

Last Version

0.0.9
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Test Pojos Maven Plugin
Unit test pojos
Project URL

Project URL

https://github.com/chonton/testpojo-maven-plugin
Source Code Management

Source Code Management

https://github.com/chonton/testpojo-maven-plugin

Download testpojo-maven-plugin

How to add to project

<plugin>
    <groupId>org.honton.chas</groupId>
    <artifactId>testpojo-maven-plugin</artifactId>
    <version>0.0.9</version>
</plugin>

Dependencies

compile (7)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-core jar 2.9.8
com.fasterxml.jackson.core : jackson-databind jar 2.9.8
com.fasterxml.jackson.datatype : jackson-datatype-guava jar 2.9.8
com.fasterxml.jackson.datatype : jackson-datatype-joda jar 2.9.8
com.fasterxml.jackson.datatype : jackson-datatype-jsr310 jar 2.9.8
org.apache.maven : maven-plugin-api jar 3.0
org.reflections : reflections jar 0.9.10

provided (2)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.2
org.projectlombok : lombok jar 1.16.6

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

testpojo-maven-plugin

Test pojos using maven plugin instead of boilerplate. Just as lombok can reduce writing bolierplate for POJOs, this plugin can reduce the unit tests you need to write.

Requirements

This plugin is designed to used with jacoco maven plugin.

Maven Configuration

To include testpojo-maven-plugin in your maven build, use the following fragment in your pom.

  <build>
    <plugins>
      <plugin>
        <groupId>org.honton.chas</groupId>
        <artifactId>testpojo-maven-plugin</artifactId>
        <version>0.0.9</version>
        <executions>
          <execution>
            <id>test-pojos</id>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

testpojo-maven-plugin provides a single 'test' goal which defaults to running in the test phase.

What gets tested

How testpojo-maven-plugin works

Using Reflections, all code in the ${build.outputDirectory} is introspected. Any class with method implementations for both equals and hashCode and has a public constructor is considered a bean.

Parameter Default Description
testpojo.skip ${skipTests} Skip testing pojos

Bean test consists of the following steps.

  1. Construct bean with public constructor having least number of arguments.
  2. Execute toString() and make sure no exceptions occur.
  3. Use Jackson to marshall to Map and back to new instance of POJO.
  • Check copy.equals(original)
  • Check copy.hashCode() == original.hashCode()
  1. Use Jackson to marshall to json string and back to new instance of POJO.
  • Check copy.equals(original)
  • Check copy.hashCode() == original.hashCode()
  1. Create variants by executing each setter with value. If the Bean has a Lombok @Builder, the builder will be used to populate the bean instead of setters.
  • Check !variant.equals(original)
  • Execute steps 2-4 above

Versions

Version
0.0.9
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1