I'm trying to use a custom reporter for TestNG with the maven surefire plugin. I already have a custom listener and that seems to get picked up. However, it doesn't look like the custom reporter is being used at all:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<properties>
<property>
<name>listener</name>
<value>com.mystuff.test.TestNGListener</value>
</property>
<property>
<name>reporter</name>
<value>com.mystuff.test.MyEmailableReporter</value>
</property>
</properties>
</configuration>
</plugin>
Any idea why this is happening?
I figured this out. It looked like the following doesn't work at all:
<property>
<name>reporter</name>
<value>com.mystuff.test.MyEmailableReporter</value>
</property>
in spite of documentation to the contrary. In the TestNG class it appears that there is a method called TestNG#addListener(IReporter listener), which contrary to its name, accepts a report which implements IReporter. Maven Surefire (v2.12.1) calls this method to add listeners and reports. However, it doesn't look for reports under a property with name reporter. Instead, you have to add your custom reporter to the listener property:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<properties>
<property>
<name>listener</name>
<value>com.mystuff.test.TestNGListener,com.mystuff.test.MyEmailableReporter</value>
</property>
</properties>
</configuration>
</plugin>
Not very intuitive.
Related
I have a maven project that is running testNG tests via a Testng xml. The XML has the following listeners
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
I have 24 tests in the xml with all of them running packages e.g
<test name="First Test"
preserve-order="true">
<packages>
<package
name="testProject.first.*" />
</packages>
</test>
For some reason all 24 tests run but in the testng report I only ever see 21 tests. The 21 tests that show are not always consistent so that rules out the possibillity of a problem with the setup of some tests. I am wondering if there is possibly a max number of tests that run and if I need to combine tests? or is there a maximum number of tests parameter somewhere that can be set?
The following is my maven-surefire-plugin setup
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>
</property>
<systemPropertyVariables>
<environment>${env.browser}</environment>
</systemPropertyVariables>
<systemPropertyVariables>
<environment>${env.environment}</environment>
</systemPropertyVariables>
<systemPropertyVariables>
<environment>${env.testlinkRelease}</environment>
</systemPropertyVariables>
</properties>
<suiteXmlFiles>
<suiteXmlFile>src/testCleanup/${cleanup.suite}</suiteXmlFile>
<suiteXmlFile>src/limelightTests/${test.suite}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Thanks for any help.
I found the issue. I had a screenshot listener that was running after #AfterMethod had run. #AfterMethod quit the driver so the screenshot listener ended up throwing an error which was not caught and caused the test to be left out of the report.
A part of code in my pom.xml looks like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suite.xml}</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter
</value>
</property>
</properties>
<testFailureIgnore>true</testFailureIgnore>
<systemProperties>
<property>
<name>org.uncommons.reportng.title</name>
<value>${title}</value>
</property>
</systemProperties>
<argLine>-Xms128m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m
-XX:+UseConcMarkSweepGC
</argLine>
</configuration>
</plugin>
I am sending -Dtitle from my jenkins job and it's working fine. Like wise I want to change the value in tag <testFailureIgnore>true</testFailureIgnore>. But the problem here is: I don't want to change the default value. I just want to parameterize this only in case if user provide "false" value from jenkins. If user do not provide anything then it should be "true".
Create a separate profile in pom where you can provide different values.
Plugin definition in pom will contain default value.
So if you run simple maven command : mvn install it will use default value
and if you run using profile that is mvn -Pprofile install then it will use value specified in profile.
Add one property <maven.test.failure.ignore>true</maven.test.failure.ignore> under <properties> tag of your pom.
Replace line testFailureIgnore line by <testFailureIgnore>${maven.test.failure.ignore}</testFailureIgnore>.
In case of "false" you need to pass one extra parameter -Dmaven.test.failure.ignore=false
It easy. First you have to add a shell comand to your job. In this command you could make a sed comand an replace this line on the other.
Example:
sed -i 's/ <maven.test.failure.ignore>true</maven.test.failure.ignore> /<maven.test.failure.ignore>false</maven.test.failure.ignore>/g' pom.xml
I am using mockito 1.8.3, jacoco 0.72 and maven 3.0.5 surefire plugin (2.12.4) to execute unit test and generating coverage report, it was working fine.
With more and more tests are added, it starts not working. I continuously encounter out of memory error during test execution, and cannot find out a way to figure out what is wrong.
I have about 1800+ test cases with mockito as the mocking tool. It is working fine if I do not run jacoco during maven test with "org.jacoco:jacoco-maven-plugin:prepare-agent " before test phase, but as long as I add jacoco agent, I get OOO issue with PermGen full.
I already added the PermGen to 2GB by modifying MAVEN_OPTS (which should not work since surefire will fork a new process) and surefire argline argument in pom, but it does not help a lot.
I try to get a core dump when OOO occurs by adding parameter to surefire plugin, but never saw a dump file in any folder. I am suspicious that my JVM setting does not work for the surefire plugin, but not sure what is wrong. Anyone could do me a favor? Thanks.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<inherited>true</inherited>
<configuration>
<properties>
<property>
<name>argLine</name> <value>-server -ea -XX:-UseSplitVerifier -XX:MaxPermSize=2g -Xmx3g -XX:+HeapDumpOnOutOfMemoryError </value>
</property>
<property>
<name>forkMode</name>
<value>once</value>
</property>
<property>
<name>reportFormat</name>
<value>plain</value>
</property>
<property>
<name>skipTests</name>
<value>${maven.test.skip}</value>
</property>
</properties>
</configuration>
</plugin>
You need to set the memory for maven-surefire-plugin like the following:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<systemPropertyVariables>
<databaseSchema>MY_TEST_SCHEMA_${surefire.forkNumber}</databaseSchema>
</systemPropertyVariables>
</configuration>
</plugin>
[...]
</plugins>
In case you have jacoco configured along with maven failsafe plugin, then you will need to pass memory parameters to that one too:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
The process started by maven jetty plugin seems ignoring any environment variables I specify.
So far I've tried adding variable through command line like:
set myvariable=1
Also I've tried adding something like "-Dmyvariable=1" to MAVEN_OPTS variable.
Nothing helps.
Just to be clear, I need to pass variable not to maven but to the resulting process, i.e. directly to jetty server.
You need to specify a systemProperties section in the plugin's configuration:
<project>
...
<plugins>
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
...
<systemProperties>
<systemProperty>
<name>myvariable</name>
<value>1</value>
</systemProperty>
...
</systemProperties>
</configuration>
</plugin>
</plugins>
</project>
I have a maven profile and want to set a property which is later on available per System.getProperty(..) in java:
<profile>
<id>local-dev</id>
<properties>
<my.comp.my.prop>myValue</my.comp.my.prop>
</properties>
</profile>
I want System.getProperty("my.comp.my.prop") to be "myValue" but it's null..
How do I set it correctly? :)
Thansk!
properties-maven-plugin plugin will help you to do exactly what you're looking for:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
<configuration>
<properties>
<property>
<name>my.property.name</name>
<value>my.property.value</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
maven cannot set a property which can be accessed by your application from the environment at runtime.
Instead, you can use maven to update a property file in your codebase during build time, which can then be read by your application at runtime. Different values of the property can be set based on the profile, thereby allowing your application to have different values as desired.
Alternately, you can invoke the application setting the desired property in the environment manually (outside maven).