Configuring Maven to Run Tests in Drone CI
When using Maven in a Drone CI pipeline, you might encounter issues where tests are skipped by default. This guide will help you configure your pom.xml correctly to ensure that your tests run as expected.
Maven Profile Example
Here’s an example of a Maven profile that includes necessary dependencies and configurations to run tests:
<profile>
<id>jsf-test</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<version>${jboss.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jsf.tests</groupId>
<artifactId>jsf-app</artifactId>
<version>${jsf-app.version}</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-jsf-app</id>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.jsf.tests</groupId>
<artifactId>jsf-app</artifactId>
<version>${jsf-app.version}</version>
<type>war</type>
<destFileName>jsfapp.war</destFileName>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<skipTests>false</skipTests> <!-- Ensure tests are not skipped -->
<properties>
<property>
<name>listener</name>
<value>${testng.listeners}</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Running Tests in Drone
To execute your tests in Drone, use the following command in your .drone.yml pipeline configuration:
steps:
- name: build
image: maven:3.5.0-alpine
commands:
- mvn -B verify -Pjsf-test
This command will compile your project and run the tests defined in your Maven profile. If you want to run a specific test, you can use:
mvn verify -Dtest=TestCalculator
Debugging Test Execution
If you find that tests are still being skipped, consider running Maven in debug mode to get more insights:
mvn -X verify -Pjsf-test
This will provide detailed logs that can help identify why tests are not being executed.
Conclusion
By properly configuring your Maven profile and ensuring that the maven-surefire-plugin is set to not skip tests, you can effectively run your tests in a Drone CI environment. Make sure to check the logs if you encounter any issues during the build process.