20

so we got the message

Process finished with exit code 0
Empty test suite.

When trying to run Junit5 testscases on our multi module project, so for testing the sources of the issue, I decided to try a new project from scratch (I am using IntelliJ IDEA 2018.2.4).

I am getting the same issue with the following simple project POM file:

<?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>com.org.bu.dep.app</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.0.5.RELEASE</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>5.3.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

I tried with/without the junit-vintage-engine same results.

Follows is the test class:

package com.org.bu.dep.app.demo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class DemoApplicationTests {

    @Test
    public void contextLoads() {
        Assertions.assertTrue(true);
    }

}

On the Run window, it says No tests were found.

I tried many variations such as with/without @SpringBootTest annotation, I tried @ExtendWith(SpringExtension.class) as well to no avail.

I already googled and most results/SackOverflow answers seem to be from 2016/2017 focused on older versions of IntelliJ which had issues with Junit 5, which do not seem to be related.

Please, any advice? If we spend too much time on it will be forced to revert to 4, and I very much do not wish to do that :)

2
  • Where is test file in project structure? Nov 7, 2018 at 21:06
  • Under /src/test/java/package.name.long... java is what is marked as test sources Nov 8, 2018 at 14:20

10 Answers 10

29

In my case, I had a private test method - it should be public.

0
21

So, what works for Junit 5 with Spring Boot 2 is the following 3 TOGETHER:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.3.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.3.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-params</artifactId>
    <version>5.3.1</version>
    <scope>test</scope>
</dependency>

Tested and verified with empty project.

Please note that @Michael Legart's answer suggesting to add

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.1</version>
</plugin>

Is needed for maven test (and Jenkins) to detect and execute the tests!

1
  • This worked for me. Though I have added maven surefire plugin of version 3.0.0.M4 Apr 20, 2023 at 10:13
9

Adding mine to the list of "dumb" mistakes: I imported the wrong @Test annotation. Junit5 will only consider methods annotated with org.junit.jupiter.api.Test and not org.junit.Test.

6

What worked for me.

Don't use the version yourself add junit-bom

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>5.6.1</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <scope>test</scope>
    </dependency>

Also with maven-surefire-plugin don't add the version

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
5

I'm pretty sure this is because Spring Boot 2 is not using the required Maven Surefire plugin version for JUnit 5. Try with:

   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.22.1</version>
   </plugin>

JUnit5 support was added in 2.22.0, see https://issues.apache.org/jira/browse/SUREFIRE-1330

2
  • That didnt work either, I just tested. What worked is added junit-jupiter-api and junit-jupiter-params dependencies Nov 8, 2018 at 14:15
  • You were actually close - this plugin is required for maven test to run! Its not required to run via IntelliJ, but is for maven test as well as for Jenkins to work. So thumbs up on a helpful answer! Nov 9, 2018 at 15:45
2

Go to: File -> Project Settings -> Modules and add the below dependency.

add dependency

add 'com.github.database-rider:rider-junit5:1.2.5'

enter image description here

'com.github.database-rider:rider-junit5:1.2.5' will make tests find and run.

1

Since you're using Intellij. Did you mark your java test folder as Test Sources Root?

Example:

enter image description here

1
  • 1
    Yes, it was not that... Turns out the missing part was adding junit-jupiter-api and junit-jupiter-params dependencies to the project! I am not sure why though...lol Nov 8, 2018 at 14:10
0

Using IntelliJ, I had to delete the target folder and run tests to get rid of this error

1
  • Your solution adds nothing above the existing accepted answer, although I'm glad it worked for you.
    – Jad
    Mar 3, 2021 at 14:30
0

I know this is an old question but maybe it helps someone. I got the error message because I copy-pasted a method from a scratch file where the method was declared static.

0

If you write your tests in interfaces or abstract classes, e.g.

public interface FooTests() {

  @Test
  default void fooTest() {
    ...
  }
}

which then get implemented by a "real" tester class,

public class Tester() implements FooTests, BarTests {
  ...
}

then what might be happening is that you ran one of those tests for the first time by itself, causing IntelliJ to remember its run configuration thereafter as FooTests::fooTest when really it needs to be Tester::fooTest. You can override this by modifying the test's run configuration, e.g.

enter image description here

You want to replace the Method: class with your non-interface, non-abstract test runner class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.