seeker
seeker

Reputation: 6991

How do I run a junit test only after the build?

How do I run a Junit test case after the build is complete. I have a piece of code that looks at autogenerated files by Maven such as Manifest.MF. Now, while running a clean build, this test will fail because the file hasnt been generated yet.

Is there any way for me to run this test after the build is complete?

Upvotes: 1

Views: 1867

Answers (2)

khmarbaise
khmarbaise

Reputation: 97389

I assume you are looking for maven-failsafe-plugin which is intended to run integration tests which are after the packaging phase where all stuff has been generated.

You need to add the following to your pom file:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.22.1</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Now you have to name your test according to the naming schemata like XyzIT.java which will be picked up by maven-failsafe-plugin and will run this test after the packaging phase. This can be achieved by:

mvn clean verify

Upvotes: 2

CharlieS
CharlieS

Reputation: 1452

include a dependency of maven-surefire plugin in pom.xml, which runs junit tests automagically if you followed junit conventions properly

Upvotes: 0

Related Questions