maven-surefire-plugin is designed for running unit tests and if any of the tests fail then it will fail the build immediately.
maven-failsafe-plugin is designed for running integration tests, and decouples failing the build if there are test failures from actually running the tests.
Visit this link for your reference, | Attaching tests
Surefire does not support tests or any referenced libraries calling System.exit() at any time. If they do so, they are incompatible with Surefire and you should probably file an issue with the library/vendor. Alternatively the forked VM could also have crashed for a number of reasons. Look for the classical "hs_err*" files indicating VM crashes or examine the Maven log output when the tests execute. Some "extraordinary" output from crashing processes may be dumped to the console/log. If this happens on a CI environment and only after it runs for some time, there is a fair chance your test suite is leaking some kind of OS-level resource that makes things worse at every run. Regular OS-level monitoring tools may give you some indication.
After a forked JVM has crashed the console of forked JVM prints Crashed tests: and lists the last test which has crashed. In the console log you can find the message The forked VM terminated without properly saying goodbye.
Use the following configuration:
<useSystemClassLoader>true</useSystemClassLoader>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkCount>1</forkCount>
Try reuseForks=true and if it doesn't work, fall back to reuseForks=false
Maven does property replacement for
${...}
Since the Version 2.17 using an alternate syntax for these properties,
@{...}
By default maven-failsafe-plugin uses project artifact file in test classpath if packaging is set to "jar" in pom.xml. This can be modified and for instance set to main project classes if you use configuration parameter "classesDirectory". This would mean that you set value "${project.build.outputDirectory}" for the parameter "classesDirectory" in the configuration of plugin.
By default maven-failsafe-plugin and maven-surefire-plugin dumps fatal errors in dump files
and these are located in target/failsafe-reports and target/surefire-reports.
Names of dump files are formatted as follows:
[date]-jvmRun[N].dump
[date]-jvmRun[N].dumpstream
[date].dumpstream
[date].dump
Forked JVM process and plugin process communicate via std/out. If this channel is corrupted, for a whatever
reason, the dump of the corrupted stream appears in *.dumpstream.
If your tests use native library which prints to STDOUT this warning message appears because the library
corrupted the channel used by the plugin in order to transmit events with test status back to Maven process.
It would be even worse if you override the Java stream by System.setOut because the stream is also
supposed to be corrupted but the Maven will never see the tests finished and build may hang.
This warning message appears if you use FileDescriptor.out or JVM prints GC summary.
In that case the warning is printed
"Corrupted STDOUT by directly writing to native stream in forked JVM", and a dump file can be found
in Reports directory.
If debug level is enabled then messages of corrupted stream appear in the console.