Why no test is run when execute mvn test -P{profile Id} - java

I have defined my profiles in pom.xml as below:
<profiles>
<profile>
<id>Test123</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/target/testdemo.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
And we I ran a command mvn test -PTest123, there is no Tests being run as shown as below:
cmd output
However, we I ran with command mvn test, it has ran the test as shown as below:
cmd output

After reviewing the output files I noticed that different versions of the maven-compiler-plugin and maven-surefire-plugin are running per profile. Is this project dependent on a parent pom.xml? Otherwise changing the versions on the plugins to:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/target/testdemo.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
should fix the problem in case the versioning is not important.

Related

Setting VM argument via pom.xml

I need to set -Duser.language via pom.xml since I need language specific database queries.
When I pass -Duser.language=tr to VM options upon running spring boot application on Intellij, it works. But I need this to be done in pom.xml for profiling.
Below ways are not working. Language is not set.
<profile>
<properties>
<argLine>-Duser.language=tr -Duser.region=TR</argLine>
</properties>
...
</profile>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<verbose>true</verbose>
<fork>true</fork>
<compilerArgs>
<arg>-J-Duser.language=tr_TR</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Duser.language=tr -Duser.region=TR</argLine>
<systemPropertyVariables>
<user.language>tr</user.language>
<user.region>TR</user.region>
</systemPropertyVariables>
</configuration>
</plugin>
Only this is working but I need to run application with mvn spring-boot:run for this to work and that is not an option.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Duser.language=tr
</jvmArguments>
</configuration>
...
</plugin>
How can I pass vm arguments via pom.xml?

Possible to target specific TestNG.xml files via Maven POM File?

Possible to target only one of the two TestNG xml files listed within my Maven POM File?
My Maven POM file points to two xml files: uat.xml and preprod.xml, how do i target only one of the xml files using maven commands such as mvn clean compile test?
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<!--<executable>C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe</executable> -->
<executable>${env.JAVA_HOME}\bin\javac.exe</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>uat.xml</suiteXmlFile>
<suiteXmlFile>preprod.xml</suiteXmlFile>
</suiteXmlFiles>
<testErrorIgnore>false</testErrorIgnore>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
See below. You will reference the file by name. So,
mvn clean test -Dtestfile=uat.xml
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${testfile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>

Dynamically Include and Exclude for maven-surefire-plugin

Could you please advise me on whether or not I can dynamically change Include and Exclude for the Maven Surfire Plugin?
For example:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/${param}Spec*.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
I would like to have $param passed from the command line when we perform the Maven test command.
Please give advice if you have a solution. I have tried argline and systemProperties
Thanks!
I don't think there is a way to pass dynamic parameter, but you can use below trick if you have limited combinations of exclusions/inclusions. Trick is using profiles with different combinations like combo1, combo2 etc. Then you can run maven build with specific profile & only those include/exclude will work.
Command = mvn clean package -P combo1
pom.xml
<profiles>
<profile>
<id>combo1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/Combo1Spec*.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>combo2</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/Combo2Spec*.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Plain Selenium and Thucydides reports

I have plain seleneum ui tests and I want to have nice thucydides reports after how can I do this.
In maven pom.xml I have profile like this:
<profile>
<id>MobileTests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
<argLine>-Dwebdriver.remote.url=http://192.168.1.5/wd/hub</argLine>
<groups>ru.testgroups.mobile.AllMobile</groups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>net.thucydides.maven.plugins</groupId>
<artifactId>maven-thucydides-plugin</artifactId>
<version>${thucydides.version}</version>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
</profile>
It suppose to generate reports, but it does not. How can I get thucydides reports from plain selenium tests
You should add the serenity (or thucydides, if you're using an older version) as a reporting plugin:
<reporting>
<plugins>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
</plugin>
</plugins>
</reporting>

Maven Surefire: Running tests in specified dependencies

I have a project that includes multiple other jar artifacts as dependencies. I'm using the surefire plugin's dependenciesToScan property to run tests in the said artifacts as follows:
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<dependenciesToScan>
<dependency>com.example.tests:project-a</dependency>
<dependency>com.example.tests:project-b</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.example.tests</groupId>
<artifactId>project-a</artifactId>
</dependency>
<dependency>
<groupId>com.example.tests</groupId>
<artifactId>project-b</artifactId>
</dependency>
</dependencies>
Ideally, I would like to be able to do the following:
mvn test would run the tests in each dependency like normal
Another parameter would run only the tests for whichever artifact is specified and skip the tests for whatever dependency was not included
Is this possible at all or is there another way to approach this?
You can use profiles to have two distinct builds.
<profiles>
<profile>
<id>project-a</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<dependenciesToScan>
<dependency>com.example.tests:project-a</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>project-b</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<dependenciesToScan>
<dependency>com.example.tests:project-b</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The use mvn clean test -P project-a or mvn clean test -P project-b
You could also set different properties in each profiles and have a centralized surefire config.
Or you could use a property:
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<dependenciesToScan>
<dependency>${someProperty}</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
The use mvn clean test -DsomeProperty=project-a

Categories

Resources