Configuration to run surefire plugin for unit, integration and BDD specs.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.adoc
bumpver.sh
pom.xml
release.sh

README.adoc

java-mavenmixin-surefire

This module, for use within Apache Isis applications, provides a maven mixin that configures the Maven surefire plugin to run unit tests, integration tests and BDD specs as separate executions. This reduces the size of the maven pom.xml file for that consuming module; it simply needs to reference this module using the mixin-maven-plugin.

The appropriate configuration is included in a <profile> which is automatically included in all builds. This profile can be disabled using a Maven property.

Note

This module was initially developed for use within Apache Isis applications but can be used by any Java application with these different types of tests.

How to Configure

To configure:

  • copy and paste the following into either the pom.xml of the consuming module or (better still) the pom.xml of the top-level parent of the consuming module:

    <properties>
        ...
        <mavenmixin-surefire.version>0.0.4</mavenmixin-surefire.version>
        <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
        <maven-surefire-report-plugin.version>2.19.1</maven-surefire-report-plugin.version>
        ...
    </properties>

    and:

    <build>
        <pluginManagement>
            <plugins>
                ...
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven-surefire-plugin.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-report-plugin</artifactId>
                    <version>${maven-surefire-report-plugin.version}</version>
                </plugin>
                ...
            </plugins>
        </pluginManagement>
    </build>
  • add the following to the pom.xml of the consuming module (containing tests of any sort):

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.odavid.maven.plugins</groupId>
                <artifactId>mixin-maven-plugin</artifactId>
                <version>0.1-alpha-39</version>
                <extensions>true</extensions>
                <configuration>
                    <mixins>
                        <mixin>
                            <groupId>com.danhaywood.mavenmixin</groupId>
                            <artifactId>surefire</artifactId>
                            <version>${mavenmixin-surefire.version}</version>
                        </mixin>
                    </mixins>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • optionally, configure the isis.integTest.module property:

    To disable the (profile contributed by this) mixin, pass the following system property to mvn:

    <properties>
        <isis.integTest.module>com.mycompany.myapp.MyApplicationModule</isis.integTest.module>
        ...
    </properties>

    This will be passed through as a system property when running integration tests. For integration tests extending from IntegrationTestAbstract3, this is used as an override to bootstrap the application with some other, usually larger, set of modules. This is needed to avoid the framework (attempting to) teardown and reinitialize the runtime for integration tests that are each bootstrapped with a different Module.

  • optionally, configure the surefire-plugin.argLine property:

    <properties>
        <surefire-plugin.argLine>-Xms1024m -Xmx1024m</surefire-plugin.argLine>
    </properties>

    This is passed through to each surefire invocation (run in forked mode).

How to Use

The mixin configures the surefire plugin for three separate executions:

  • mvn test

    Runs all unit tests, matching the name *Test*.java. However, this excludes integration tests matching *IntegTest*.java (see below). It also ignores classes named *Testing.java, eg stub classes such as CustomerForTesting.java.

  • mvn verify

    Runs the unit tests (because test phase precedes verify phase) and also the integration tests and Cucumber BDD specs. Integration tests must match the name *IntegTest*.java. BDD spec runners must match the name *IntegBddSpecs*.java.

    Tip

    In fact the executions are bound to Maven’s integration-test phase, but "verify" is shorter to type.

If any of the unit tests or integration tests fail, then the build will fail. For BDD specs, though, a failing spec will not cause the build to fail. This allows a report of the BDD specs to then be generated (see danhaywood/mavenmixin-cucumberreporting).

It’s also possible to skip any one of these types of tests:

  • mvn -DskipUTs

    will skip running unit tests

  • mvn -DskipITs

    will skip running integration tests

  • mvn -DskipBSs

    will skip running the BDD specs

The usual mvn -DskipTests can also be used to skip all tests.

Known issues

None currently

Change Log

  • 0.0.6 - support surefire-plugin.argLine property, and run in forked mode

  • 0.0.5 - support isis.integTest.module property

  • 0.0.4 - updates README for properties and plugin management, shortens property names and profile id

  • 0.0.3 - relaxes naming convention for unit tests: will now match Test*.java and *Test.java, but excludes *IntegTest*.java and *Testing.java (eg CustomerForTesting.java) Also, introduces properties to fix down the plugin versions.

  • 0.0.2 - fixes issue with -DskipITs, also ensure that BDD specs are always run. Removes the optional configuration property defining the plugin version (seemed to be ignored). References the danhaywood/cucumberreporting maven mixin in the README.

  • 0.0.1 - first release.

See also

If the consuming module defines cucumber BDD specs, then the danhaywood/mavenmixin-cucumberreporting maven mixin can be used to configure cucumber reporting plugins.

License

Copyright 2016~date Dan Haywood

Licensed under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Dependencies

This mixin module relies on the com.github.odavid.maven.plugins:mixin-maven-plugin, released under Apache License v2.0.

Maven deploy notes

The module is deployed using Sonatype’s OSS support (see user guide and this blog post).

The release.sh script automates the release process. It performs the following:

  • performs a sanity check (mvn clean install -o) that everything builds ok

  • bumps the pom.xml to a specified release version, and tag

  • performs a double check (mvn clean install -o) that everything still builds ok

  • releases the code using mvn clean deploy

  • bumps the pom.xml to a specified release version

For example:

sh release.sh 0.0.6 \
              0.0.7-SNAPSHOT \
              dan@haywood-associates.co.uk \
              "this is not really my passphrase"

where

  • $1 is the release version

  • $2 is the snapshot version

  • $3 is the email of the secret key (~/.gnupg/secring.gpg) to use for signing

  • $4 is the corresponding passphrase for that secret key.

Other ways of specifying the key and passphrase are available, see the pgp-maven-plugin's documentation).

If the script completes successfully, then push changes:

git push origin master
git push origin 0.0.6

If the script fails to complete, then identify the cause, perform a git reset --hard to start over and fix the issue before trying again. Note that in the dom’s `pom.xml the nexus-staging-maven-plugin has the autoReleaseAfterClose setting set to true (to automatically stage, close and the release the repo). You may want to set this to false if debugging an issue.

According to Sonatype’s guide, it takes about 10 minutes to sync, but up to 2 hours to update search.