1

Editing to add additional information at the bottom

I've looked here: What is a good way in maven/surefire to clean up after unit tests, whether they pass or not? but it's not helping me. I'm probably configuring failsafe and/or surefire incorrectly.

I have jUnit tests that depend on configuration files being in place, and I've added copy-rename-maven-plugin in the process-test-resources phase to set up test copies of the config files for the jUnit tests, and copy-rename-maven-plugin and maven-clean-plugin in the post-integration-test phase to restore everything back the way it was when I'm done. But when the jUnit tests fail, the subsequent phases aren't running, even though I have failsafe plugin as well.

The jUnit examples in the failsafe documentation all use surefire, so I'm confused about how to get failsafe to run them - or if that's even what I need to do.

I've got jUnit declared as a dependency

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
</dependency>

I've got failsafe plugin in the build:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.20</version>
        <!--
        <configuration>
            <skipITs>true</skipITs>
        </configuration>
        -->
        <executions>
            <execution>
                <id>run-nonautowired-tests</id>
                <phase>integration-test</phase>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
                <configuration>
                    <includes>
                        <include>*Test.java</include>
                    </includes>
                </configuration>
            </execution>
        </executions>
    </plugin>

I don't have any integration tests following the *IT naming conventions, only the jUnit tests following the *Test naming conventions. I'm just trying to use failsafe as a way to ensure my cleanup gets done. I've tried skipITs true and I've tried commenting that out. I've tried with and without the configuration includes.

I've currently got surefire plugin commented out, but it's still running the tests and failing the build, based on the output I'm seeing:

    <!--
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
            <skipTests>true</skipTests>
        </configuration>
    </plugin>
    -->

What am I missing/doing wrong? It seems I had this working before, but it was running the jUnit tests twice in a different project that used Spring, where I needed to add tests that didn't use Spring - but I can't remember what I did differently.

I'm doing this inside IntelliJ 14.1.5, but running the Maven Lifecycle to the verify phase rather than having IntelliJ run the jUnit tests directly.

Also, it seems that its surefire 2.12.4 that is running the default-test, and I have no idea where that is coming from.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project RefRange: There are test failures.

Where should I look to see where 2.12.4 is coming from? And how can I get this to run the jUnit tests once, and continue on to the next phase even if they fail?

Thanks for any help,

Rebeccah


Additional information: After uncommenting my surefire plugin, adding

<skip>false</skip>
<skipTests>true</skipTests>

to its configuration, changing the failsafe includes to

<includes>**/*Test.java</includes>,

and running mvn verify -X, I get the following immediately after my intentional test failure:

[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   ref_range_by_RTest.testGetConfigManager:56
    Expected: is "C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 8.0.27/app_rsrcs/refrange/data"
         but: was "C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 8.0.27/app_rsrcs/refrange/data-not"
[INFO]
[ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting.   outputEncoding}.
[INFO]
[INFO] --- maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) @ RefRange ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:2.20, parent: sun.misc.Launcher$AppClassLoader@647e05]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify' with basic configurator -->
[DEBUG]   (s) basedir = C:\Git\clincor-clindev\refrange
[DEBUG]   (s) reportsDirectory = C:\Git\clincor-clindev\refrange\target\failsafe-reports
[DEBUG]   (s) skip = false
[DEBUG]   (f) summaryFile = C:\Git\clincor-clindev\refrange\target\failsafe-reports\failsafe-summary.xml
[DEBUG]   (s) testClassesDirectory = C:\Git\clincor-clindev\refrange\target\test-classes
[DEBUG]   (s) testFailureIgnore = false
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@2eef62
[DEBUG] -- end configuration --
[DEBUG] Failsafe report directory: C:\Git\clincor-clindev\refrange\target\failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.976 s
[INFO] Finished at: 2017-05-17T20:54:09-07:00
[INFO] Final Memory: 17M/247M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) on project RefRange: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Git\clincor-clindev\refrange\target\failsafe-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) on project RefRange: There are test failures.
Community
  • 1
  • 1
Rebeccah
  • 327
  • 1
  • 13
  • Surefire plugin is a part of [default lifecycle](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html), 2.12.4 comes from [default-bindings.xml](https://git-wip-us.apache.org/repos/asf?p=maven.git;a=blob;f=maven-core/src/main/resources/META-INF/plexus/default-bindings.xml). – default locale May 18 '17 at 03:34
  • See if this answer helps you: https://stackoverflow.com/questions/6612344/prevent-unit-tests-in-maven-but-allow-integration-tests#17932772 – default locale May 18 '17 at 03:35
  • Thanks, I've narrowed things a little bit. If I uncomment the surefire plugin in my pom.xml, I get the version in my pom.xml. If I tell skip tests in surefire, the build DOES NOT FAIL, and I can see some messages from the failsafe plugin (previously, I was gettting nothing from failsafe at all). I'm gettting "Tests are skipped" messages for both failsafe goals (integration-test and verify). – Rebeccah May 18 '17 at 03:35
  • Now if I also add false as well as true in surefire and change the failsafe includes to **/*Test.java, I get failsafe to run my tests -- but now I get "org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) on project RefRange: There are test failures." and the post-integration-test phase doesn't run. – Rebeccah May 18 '17 at 03:42
  • Have you tried to create a custom property like [here](https://stackoverflow.com/questions/6612344/prevent-unit-tests-in-maven-but-allow-integration-tests#17932772)? if you set `skip.surefire.tests` to true, this might work. – default locale May 18 '17 at 03:48
  • Thanks, the properties look like a nice way to centralize making those setting changes. I've updated my question with the debug output after I've set skip to false and skipTests to true directly in surefire. I'm not finding any helpful information there. I'll try the properties trick next. – Rebeccah May 18 '17 at 04:10
  • As far as I can understand, the problem with `skip` and `skipTests` is that they affect both surefire and failsafe. This may lead to unexpected results. Redefined properties are supposed to solve this problem. – default locale May 18 '17 at 04:13
  • 1
    I've got it to where it's failsafe that's running the tests and not surefire, that's no longer the problem. The problem now is that post-integration-test phase is not running at all when failsafe tests fail. I thought post-integration-test phase is supposed to come before verify phase. – Rebeccah May 18 '17 at 04:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144509/discussion-between-default-locale-and-rebeccah). – default locale May 18 '17 at 04:36
  • I've never been in SO chat before. I can't see where to post. – Rebeccah May 18 '17 at 04:39
  • there is a direct link in my previous comment: https://chat.stackoverflow.com/rooms/144509/discussion-between-default-locale-and-rebeccah – default locale May 18 '17 at 04:40
  • I followed it, I can't see wherre on the page to post anything. – Rebeccah May 18 '17 at 04:41
  • It says "Loading Discussion between default locale and Rebeccah Just a second..." and never seems to finish loading. I see a field that looks like I could post there, but when I click send nothing happens. If I click "show all" at the bottom of the page, the form fields are gone and no send button. – Rebeccah May 18 '17 at 04:44

1 Answers1

0

Currently, failsafe:verify is bound to the integration-test phase:

<executions>
    <execution>
    <id>run-nonautowired-tests</id>
    <phase>integration-test</phase>
    <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
    </goals>
    <configuration>
        <includes>
            <include>*Test.java</include>
        </includes>
    </configuration>
    </execution>
</executions>

failsafe will result in a failure before post-integration-test cleans up.

Try to remove <goal>verify</goal> from integration-test phase. You can create a separate execution for verify phase if you need it.

UPDATE: Consider declaring configuration properties in the plugin itself and not in the execution:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.20</version>
    <configuration>
        <includes>**/*Test.java</includes>
    </configuration>
    ...

This way you can probably omit explicitly declared executions for failsafe plugin.

default locale
  • 13,035
  • 13
  • 56
  • 62
  • That was it, thanks. I knew it had to be something simple and fundamental, but it was obscured by all of the other configuration issues. No separate execution needed (by default it's bound to verify phase, but I was explicitly binding it to post-integration-test phase). – Rebeccah May 18 '17 at 05:09
  • @Rebeccah I've updated my answer to cover possible configuration issues – default locale May 18 '17 at 05:54
  • 1
    After our discussion yesterday, I tried adding back the execution for the verify goal in verify phase. Now I get execution of the post-integration-test phase AND failure of the build in the verify phase, as it should be. – Rebeccah May 19 '17 at 05:22