FuncGen Maven Plugin

The FuncGen Maven 2 Plugin generates and runs functional tests. FuncGen consists of two goals which can be used independently or together:

  • funcgen - Generates functional tests combinations and permutations specified by a funcgen-tests.xml file.
  • funcrun - Runs a collection of Maven projects specified by pomFilePattern, includePomFiles and excludePomFiles properties.

Configuration

This plugin is used by RevGen to test various combinations of target persistence technologies, ORM (Object Relational Mappings) configurations, table types, foreign keys and databases. The example here is taken from the RevGen Functional Tests setup.

To add this plugin to your Maven 2 build process, add the following to the <build><plugins> section of your pom.xml file:

<plugin>
        <groupId>org.javagen.funcgen</groupId>
        <artifactId>maven-funcgen-plugin</artifactId>
        <version>1.0-alpha1</version>
        <executions>
                <execution>
                        <id>generate-tests</id>
                        <goals><goal>funcgen</goal></goals>
                        <phase>generate-test-sources</phase>
                        <configuration>
                                <springConfigFile>file:src/funcgen/FuncGenSpringConfig.xml</springConfigFile>
                                <baseDirectory>target/funcgen-tests</baseDirectory>
                                <properties>
                                        <version>${project.version}</version>
                                </properties>
                        </configuration>
                </execution>
                        <execution>
                        <id>run-tests</id>
                        <goals><goal>funcrun</goal></goals>
                        <phase>test</phase>
                        <configuration>
                                <baseDirectory>target/funcgen-tests</baseDirectory>
                                <goals>test</goals>
                                <pomFilePattern>*/pom.xml</pomFilePattern>
                                <goals2>site</goals2>
                                <pomFilePattern2>pom.xml</pomFilePattern2>
                        </configuration>
                </execution>
        </executions>
</plugin>

This file is configured to run during the test phase but could also be configured to run during the integration test phase by replacing the generate-test-sources and test goals with preintegration-test and integration-test goals respectively.

Here both goals are used together, the first, funcgen, generates a parent pom.xml file and a series of pom.xml child modules specified in FuncGenSpringConfig.xml. The second, funcrun, executes the tests configured in the child modules. Then it executes the site goal on the parent pom to create a consolidated test results report.

Functional Test Generation Configuration

Test generation is configured using FuncGenSpringConfig.xml which is a Spring XML bean configuration file. FuncGen is based on JavaGen Agile a template-based, highly-configurable code generation framework.

The specific tests generated are model in funcgen-tests.xml using suite, test and permutations elements:

<suite name="doa-impl">
        <!-- This tests all permutations of DAO implementations:
                daoImplType = spring, jpa, hibernate
                annotations = true, false
        -->
    <context>
        <entry key="includeTables"><value>PERSONS</value></entry>
    </context>
        <permutations name="daoImplType">
        <value>jpa</value>
        <value>spring</value>
        <value>hibernate</value>
        </permutations>
        <permutations name="annotations">
        <value>true</value>
        <value>false</value>
        </permutations>
</suite>

This model segment results in 6 tests being generated to test every combination of the 3 daoImplType settings with the 2 annotations settings.

Setting FuncGen Properties

FuncGen test generation configuration is largely handled by two files:

funcgen.properties
overrides the default properties.
FuncGenSpringConfig.xml
configures every detail of FuncGen including default properties.

Use file:src/funcgen/funcgen.properties for simple configuration. If you need more control, use file:src/funcgen/FuncGenSpringConfig.xml.

You can also override default properties within the plugin configuration section as follows:

<configuration>
   <properties implementation="java.util.Properties">
      <srcDir>src/main/java</srcDir>
      <testDir>src/test/java</testDir>
    </properties>
</configuration>

Command-line Usage

As configured above the plugin will be invoked in the test phase of the build lifecycle, so you don't need to do anything special to invoke FuncGen.

To run funcgen stand-alone type:

mvn funcgen:funcgen

To run funcrun stand-alone type:

mvn funcgen:funcrun

To run funcgen stand-alone using the groupID:artifactID:version:goal form, type:

mvn org.javagen.funcgen:maven-funcgen-plugin:1.0:funcgen