Issue
My project structure is:
Project_Name
|-src/main/java
|-src/test/java
|-default package
|-MyIT.java
|-steps
|-MySteps.java
|-pom.xml
MyIT.java:
@RunWith(SerenityRunner.class)
public class MyIT {
@Steps
MySteps mySteps;
@BeforeClass
public static void setUp() {
RestAssured.baseURI="https://restcountries.com/";
System.out.println("1");
}
@Test
@Title("Check \"Republic Of India\"")
public void verify_that_given_string_found_in_the_response() {
mySteps.whenIOpenURLForIndia();
mySteps.thenRepublicOfIndiaFoundInResponse();
}
}
MySteps.java:
public class MySteps {
@Step("When I Open the URL for India")
public void whenIOpenURLForIndia() {
SerenityRest.given().relaxedHTTPSValidation().basePath("v2/name/{country}").pathParam("country", "INDIA").when().get();
}
@Step("Then \"Republic of India\" found in the response")
public void thenRepublicOfIndiaFoundInResponse() {
SerenityRest.lastResponse().then().body("[1].altSpellings",hasItem("Republic of India"));
}
}
Pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.restcountries</groupId>
<artifactId>Serenity_RestAssured_Assignment1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Serenity_RestAssured_Assignment1</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-core -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-junit -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-rest-assured -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Now when I run it using:
mvn clean verify
its output is:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< org.restcountries:Serenity_RestAssured_Assignment1 >---------
[INFO] Building Serenity_RestAssured_Assignment1 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Serenity_RestAssured_Assignment1 ---
[INFO] Deleting C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Serenity_RestAssured_Assignment1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ Serenity_RestAssured_Assignment1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Serenity_RestAssured_Assignment1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ Serenity_RestAssured_Assignment1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ Serenity_RestAssured_Assignment1 ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ Serenity_RestAssured_Assignment1 ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar:
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\Serenity_RestAssured_Assignment1-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.305 s
[INFO] Finished at: 2022-06-24T04:14:55+05:30
It shows “tests are skipped” and “jar will be empty”.
My question is why mvn verify
is not running MyIT.java test despite that naming convention is proper for integration test(maven failsafe plugin). Maven surefire plugin is skipping the tests but maven failsafe plugin should identify the MyIT.java test.
EDIT: mvn clean test-compile failsafe:integration-test
is able to run the MyIT.java test successfully but mvn clean test-compile failsafe:verify
does not.
Solution
The issue is simply because you have defined the maven-failsafe-plugin in pluginManagement only.
The usual way is to define the version in pluginManagement while the binding has to be done in build area.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I also recommend to upgrade your used plugins which means define newer versions of all used plugin in pluginManagement.
Furthermore you should not define a configuration for maven-surefire-plugin:
<configuration>
<skip>true</skip>
</configuration>
Answered By - khmarbaise
Answer Checked By - Pedro (JavaFixing Volunteer)