Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No tests were found" with Junit 5 and IntelliJ

Q&A-Style question as the existing questions don't match the simple typo I made here:

Goal

  • Execute simple JUnit tests via the IntelliJ IDE using the UI (right-click: run test)

Problem

  • IntelliJ tells that "no tests were found"

Code

import org.junit.jupiter.api.Test;

public class Test {
    @Test
    private void testAMethod() { (...) }
}

like image 770
hb0 Avatar asked Dec 11 '19 14:12

hb0


2 Answers

change to

public void testAMethod() { (...) }

According to Junit5 document

Test classes, test methods, and lifecycle methods are not required to be public, but they must not be private.

https://junit.org/junit5/docs/current/user-guide/

like image 66
Vikki Avatar answered Oct 13 '22 11:10

Vikki


Another possibility of this error message is when using a non-void return type. Switch to void and it will work.

like image 45
Nicolas Mafra Avatar answered Oct 13 '22 11:10

Nicolas Mafra