Testing with EmbeddedKafka - Test report - maven

I'm using EmbeddedKafka to test the integration with Kafka in my microservice. And also, I'm using jacoco for publishing the test result. Inorder to make the test run without any issue, I have to make the forkCount parameter as 0.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<forkCount>0</forkCount>
<includes>
<include>**/*ITest.java</include>
</includes>
</configuration>
</plugin>
If not, it fails with error the following error:
MojoFailureException: Error occurred in starting fork, check output in log
The problem is since I'm making the forkCount as 0, the jacoco plugin fails to generate report, as it couldn't start as javaagent. Is there workaround for this?

Related

Always getting "Tests run: 0, Failures: 0, Errors: 0, "even though testng test got executed using "mvn clean test -Dsurefire.suiteXmlFiles=testng.xml"

I am expecting count for Total tests, Passed, Failed should show on console.
I am using latest Testng version 7.4.0. and 2.22.0 surefire version.
I have tried every possible solution but didn't work for me.
Please find my code for maven surefire plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${surefire.suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<includes>
<include>*.*</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reportsDirectory>target/test-report</reportsDirectory>
</configuration>
<dependencies>
</dependencies>
</plugin>
Please let me know if anyone knows any solution.

Maven(Surefire) Exclude all Unit Test Cases but run selected

My company is in the middle of revamping the java code that has been written till now. Earlier there were some test cases written, but they were not maintained. As a result they are failing.
I have inherited this project, but currently have to make do with skipping all the tests.
I want to start by picking some unit test cases within a module fix them and add it to the suite of test cases that are being run. Over a period of time, I want to cover all the tests in my project.
I have tried the following plugin configuration in my POM file, but it is not working. Is there something I am missing ?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<skipTests>${skipTests}</skipTests>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
<includes>
<include>**/ParticularSubModuleTest.java</include>
</includes>
</configuration>
</plugin>

I'm getting an error from Maven saying "There are test failures", but I didn't write any test failures

This is the following error:
And these are the failed reports:
I'm completely new to maven so I'm not sure what any of this means
To clarify, maven is saying that it failed to execute it's goal (which was verify in this case). If you aren't running any test suites, maven will always record a failure, because it is configured to fail a build when you don't have any tests to run.
There are configurations which will allow maven to build successfully with no tests that can be set in your pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<failIfNoTests>false</failIfNoTests>
</configuration>
</plugin>
With this adjustment, maven will still build when you don't specify any tests. You never specified in your original post what your tests (if you have any) look like, so it's impossible to see if this is what the error is, or something else.
You need to find a way to ignore the test cases. Adding the following maven plugin solves the issue.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>

Surefire system property not being set

I'm trying to get our Mule tests to run with verbose exceptions, but I cannot get the surefire plugin to set the appropriate system property correctly, here is my surefire config:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<mule.verbose.exceptions>true</mule.verbose.exceptions>
</systemPropertyVariables>
</configuration>
Now if I run maven with the command -Dmule.verbose.exceptions=true it prints verbose exceptions, but will not if I do a simple mvn test. Why are my system properties being ignored here?
I haven't checked the code but it could be caused by a static check that is performed previous to the surefire initialization. I would rather try the special variables mechanism described in the documentation.

Make maven's surefire show stacktrace in console

I'd like to see the stacktrace of unit tests in the console. Does surefire support this?
A related problem that I found is that surefire in recent versions apparently sets trimStackTrace to true by default (rendering most stack trace in failed tests useless), which is quite inconvenient.
Setting -DtrimStackTrace=false or defining
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
solved this.
You can use the following command to see the stack trace on console instead of report files in the target/surefire-reports folder:
mvn -Dsurefire.useFile=false test
To extend the answer given before, you also can configure this behavior in your pom.xml:
..
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<useFile>false</useFile>
</configuration>
</plugin>
..

Resources