When using Tycho to build a project, the test cases are run in a new process using the equinox launcher to run -application org.eclipse.tycho.surefire.osgibooter.headlesstest.
How can I debug the test cases?
There is a much easier way to accomplish this:
just add -DdebugPort=8000 to your Maven commandline and attach a remote debug session.
See the docs https://www.eclipse.org/tycho/sitedocs/tycho-surefire-plugin/test-mojo.html#debugPort
Add this to your POM:
<profiles>
<profile>
<id>debug</id>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<argLine>-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Now you can enable debugging with mvn ... -P debug when the following line is printed:
Listening for transport dt_socket at address: 8000
See the Eclipse help how to configure the IDE.
Related
It is in my understanding that when a profile is explicitly set with the -P option, it is exclusive and that profile should get activated no matter what.
In my case, after running the command mvn clean compile -Pcross-compile, the cross-compile profile was ignored and build-linux-amd64 was activated instead.
What is going on here and why is cross-compile not being called?
My profile configuration below:
<profiles>
<!-- Cross-compile profile (can only be run under linux os) -->
<profile>
<id>cross-compile</id>
<properties>
<current-os>linux</current-os>
<current-arch>amd64</current-arch>
<crossCompile>true</crossCompile>
<build-target>native-build-cc-all</build-target>
</properties>
<build>
<plugins>
<!-- Enforcer: Make sure this can only be run from the Linux OS -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-os</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireOS>
<name>Linux</name>
<family>unix</family>
<arch>amd64</arch>
</requireOS>
</rules>
<failFast>true</failFast>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- BUILD PROFILE: Linux - x86_64/amd64 -->
<profile>
<id>build-linux-amd64</id>
<activation>
<os>
<name>linux</name>
<family>unix</family>
<arch>amd64</arch>
</os>
<property>
<name>!crossCompile</name>
</property>
</activation>
<properties>
<current-os>linux</current-os>
<current-arch>amd64</current-arch>
<build-target>native-build-linux-x86_64</build-target>
</properties>
</profile>
</profiles>
pom.xml source code here
Travis CI Log here
Looks like I need to explicitly deactivate the build-linux-amd64 profile. I compiled using
mvn clean compile -P'cross-compile,!build-linux-amd64'
and now it works as expected.
From what you provided in Travis log, I find you are running maven with
mvn --settings scripts/settings.xml install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V
In this step, you were compiling the code without profile option.
Then you run
mvn package -Pcross-compile -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true.
In this packing step, the code is compiled. So mvn will not use the compile options in the profile to compile the code again.
So try to add the profile option in the first mvn install command.
I have a JUnit 4.12 SlowTests test suite that I want to exclude from execution unless specifically requested on the Maven command line.
I have added the following to my pom file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<excludedGroups>com.Example.SlowTests</excludedGroups>
<includes>
<include>**/*TestSuite.class</include>
</includes>
<excludes>
<exclude></exclude>
</excludes>
</configuration>
</plugin>
I have defined the category as SlowTests and applied it to the MySlowTests class.
I have annotated the test suite as follows:
#RunWith(Categories.class)
#IncludeCategory(SlowTests.class)
#SuiteClasses({ MySlowTests.class })
public class MySlowTestSuite
When I run mvn package all the unit tests except MySlowTests are executed.
However, looking at various answers such as https://stackoverflow.com/a/25639372/820657 and https://stackoverflow.com/a/21830866/820657 I expected the following command:
mvn package -Dgroups=com.Example.MySlowTests
to run the excluded MySlowTests tests but they don't run. In fact no tests run.
What am I doing wrong?
The Maven Surefire plugin has some issues w.r.t categories in versions < 2.13 (IIRC) but as long as you are using Surefire >= 2.13 the following will run any classes annotated with #Category(com.yourcompany.SlowTests.class):
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<groups>com.yourcompany.SlowTests</groups>
</configuration>
</plugin>
This approach is often used with profiles, the following configuration ...
<profiles>
<profile>
<id>slow</id>
<properties>
<testCategories>com.yourcompany.SlowTests</testCategories>
</properties>
</profile>
<profile>
<id>fast</id>
<properties>
<testCategories>com.yourcompany.FastTests</testCategories>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<groups>${testCategories}</groups>
</configuration>
</plugin>
</plugins>
</build>
... can be used to run:
mvn install -P slow: runs the slow tests only
mvn install -P fast: runs the fast tests only
mvn install -P fast,slow: runs the fast and slow tests
Update 1: for this question: "Is there a way to use this approach so I can run all fast tests by default?"
You can define two properties:
<properties>
<includedCategories></includedCategories>
<excludedCategories>com.yourcompany.SlowTests</excludedCategories>
</properties>
Then update your surefire plugin definition like so:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<groups>${includedCategories}</groups>
<excludedGroups>${excludedCategories}</excludedGroups>
</configuration>
</plugin>
And, finally, add this profile:
<profile>
<id>slow</id>
<properties>
<includedCategories>com.yourcompany.SlowTests</includedCategories>
<excludedCategories></excludedCategories>
</properties>
</profile>
This just toggles the includedCategories and excludedCategories properties. By default, you include everything except those tests annotated with com.yourcompany.SlowTests (i.e. everything except your 'slow' tests). When you run with -P slow you exclude everything except those tests annotated with com.yourcompany.SlowTests (i.e. everything except your 'slow' tests).
Note: what I said in my original answer about Surefire versions < 2.13 misbehaving with Categories still stands so to make this work you need to be using a version of the Maven Surefire plugin >= 2.13.
I am trying to specify, in my maven settings.xml and my pom.xml, which jvm to use for my gwt project.
I am using the suggestion from https://stackoverflow.com/a/20787334/265119. I have used this on other, non-gwt projects successfully.
Now however it seems that maven is ignoring this, and continues to use java 8, whereas I have set the following in my settings.xml:
<profiles>
<profile>
<id>default</id>
<properties>
<JAVA_1_7_HOME>/usr/lib/jvm/java-7-oracle/bin/javac</JAVA_1_7_HOME>
<JAVA_1_8_HOME>/usr/lib/jvm/java-8-oracle/bin/javac</JAVA_1_8_HOME>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
And in my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<executable>${JAVA_1_7_HOME}</executable>
</configuration>
</plugin>
Does anyone know why maven is ignoring these?
Does the gwt maven plugin also need to specify the jvm version?
Thanks
Is the profile really activated? Your POM ought to work, but only if the profile is activated.
You can run mvn help:active-profiles to find out if your profile is active.
Also, in order for <executable> to work, you need to set <fork>true</fork> as well. As explained here: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#executable
I see a lot of posts on here about running a TestNG suite using Maven surefire plugin. The examples say to add this to the pom:
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${testSuite}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
And then this to the command line:
mvn test -DtestSuite=myCustomSuite.xml
My problem with this is that it ties you to using the TestNG suite... For example, if I want to run with groups like this:
mvn test -Dgroups=myGroup
I get this error:
maven-surefire-plugin:2.18.1:test failed: testSuiteXmlFiles0 has null value
I want to be able to run, from command line, passing in either a suite path or groups.
Instead of using your surefire configuration with a property, you can:
Remove the surefire configuration and replace mvn test -DtestSuite=myCustomSuite.xml by mvn test -Dsurefire.suiteXmlFiles=myCustomSuite.xml. See Surefire documentation
Continue to use the mvn test -Dgroups=myGroup.
As the surefire configuration will be removed, the error testSuiteXmlFiles0 has null value won't be present with the -Dgroup option.
You can also use maven profiles which will configure surefire plugin depending on which property you pass to maven.
<profiles>
<profile>
<id>suite</id>
<activation>
<property>
<name>testSuite</name>
</property>
</activation>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${testSuite}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</profile>
</profiles>
For some reason, the accepted answer didn't work for me. I used something like following.
mvn test -Dgroups=myGroup -DtestSuite=" "
When using the maven release plugin, both mvn release:prepare and mvn release:perform will run the tests.
Is there any way I can configure things so they only run during mvn release:prepare?
I know you can pass:
-Darguments="-DskipTests"
But this will skip the tests during both goals, which I don't want. And I also don't want them to run during just mvn release:perform and not prepare, as a failure during perform will have already tagged the repository.
You should be able to do that by adding the <releaseProfiles> element to the release-plugin configuration. This will only be used for release:perform Mojo.
Something like this should do the trick:
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<releaseProfiles>skipTestsForReleasePerform</releaseProfiles>
</configuration>
</plugin>
</plugins>
</build>
(...)
<profiles>
<profile>
<id>skipTestsForReleasePerform</id>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</profile>
</profiles>