Reputation: 4136
I'm trying to figure this out for over a year now but I can't run JUnit5 suites unless I use the JUnit4 @RunWith annotation, which brings me some other issues. I'm trying to use the newer @Suite
annotation instead but no matter what I try (name the test ending with IT, Test, run through IntelliJ, run through maven, include tag, exclude tag, etc), I keep getting the tests no found error. I think I'm really running out of ideas at this stage and would love someone to point it out what is it that I may still be missing.
<?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.example</groupId>
<artifactId>pact</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>8</java.version>
<maven.compiler.version>1.8</maven.compiler.version>
<maven.target.version>1.8</maven.target.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>vcservice</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<testSourceDirectory>src/test/java/com/hmhco/vcservice</testSourceDirectory>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>
</project>
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
class GoogleTest {
@Tag("google")
@Test
void testing() {
System.out.println("testing google");
}
}
Thank you very much.
Update
Added some more dependencies, which failure by failure have now brought me to this new error and updated pom file.
import org.junit.platform.suite.api.IncludeTags;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
@SelectPackages("com.my.package")
@IncludeTags("google")
@Suite
public class TestSuiteGoogle {
}
<?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.example</groupId>
<artifactId>pact</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>8</java.version>
<maven.compiler.version>1.8</maven.compiler.version>
<maven.target.version>1.8</maven.target.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
<junit.jupiter.version>5.0.0-M2</junit.jupiter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.7.0</version>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>vcservice</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<testSourceDirectory>src/test/java/com/hmhco/vcservice</testSourceDirectory>
<trimStackTrace>false</trimStackTrace>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-logger-api</artifactId>
<version>2.21.0</version>
<!-- to get around bug https://github.com/junit-team/junit5/issues/1367 -->
<scope>test</scope>
<optional>true</optional>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Upvotes: 3
Views: 3454
Reputation: 1
I had the same issue as what u described in your above post, and I fixed it with following solution:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<version>1.11.3</version>
<scope>test</scope>
</dependency>
<configuration>
<test>com.x.y.z.TestSuiteClass</test>
</configuration>
Upvotes: 0
Reputation: 43
The Junit 5 User Guide states:
In addition to the junit-platform-suite-api and junit-platform-suite-engine artifacts, you need at least one other test engine and its dependencies on the classpath.
Your project does not include the junit-platform-suite-engine
. Please add the following dependency to your project:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<scope>test</scope>
</dependency>
Upvotes: 4