Right Click on Project > Properties > Java Build Path > Add the Test folder as source folder.

All source folders including Test Classes need to be in Eclipse Java Build Path. So that the sources such as main and test classes can be compiled into the build directory (Eclipse default folder is bin).

Answer from iaacp on Stack Overflow
🌐
GitHub
github.com › mockito › mockito › issues › 2082
'this' is not available - when enabling mock-maker-inline · Issue #2082 · mockito/mockito
October 28, 2020 - When we enable mock-maker-inline ... 'this' is not available: When we unset mock-maker-inline then things work as expected and we can inspect the class variables: It appears to be the same as this report: https://stackoverflow.com/questions/62661996/unable-to-debug-junit-test-a...
Author   leonroy
Discussions

java - No tests found with test runner 'JUnit 4' - Stack Overflow
Warning 'No JUnit tests found' occures because there is no unitTests.class files in your 'build' directory ... This is the solution that works for me. Restarting doesn't work. 2012-08-11T10:45:25.183Z+00:00 ... This is what I was after since I have to have the "test" folder not in the "src" folder. More on stackoverflow.com
🌐 stackoverflow.com
Running Junit Test on a Single File[Resolved] - Quality Assurance - OpenMRS Talk
I am working with tests cases under referenceapplication-ui-tests. I want to be able to run a single file in my IDE. On the encounter of running a single file as Junit test, a pop up appears No tests found with test runner 'JUnit5'. Am able to see junit4.13.jar as one the maven dependency in ... More on talk.openmrs.org
🌐 talk.openmrs.org
0
March 1, 2021
java - Maven not running JUnit 5 tests - Stack Overflow
I'm trying to get a simple junit test running with maven but it is not detecting any tests. Where am I going wrong? The project directory Project -> src -> test-> java -> MyTest.java R... More on stackoverflow.com
🌐 stackoverflow.com
java - Junit method not found - Stack Overflow
Looks like assertTrue is not available but the junit javadoc mentions this method. More on stackoverflow.com
🌐 stackoverflow.com
November 6, 2011
🌐
JUnit
junit.org › junit4 › faq.html
JUnit – Frequently Asked Questions
How you configure this depends on the debugger you prefer to use. Most Java debuggers provide support to stop the program when a specific exception is raised. Notice that this will only launch the debugger when an expected failure occurs. ... Wikipedia maintains a list of available xUnit testing ...
🌐
OpenMRS
talk.openmrs.org › development › quality assurance
Running Junit Test on a Single File[Resolved] - Quality Assurance - OpenMRS Talk
March 1, 2021 - I am working with tests cases under referenceapplication-ui-tests. I want to be able to run a single file in my IDE. On the encounter of running a single file as Junit test, a pop up appears No tests found with test runner 'JUnit5'. Am able to see junit4.13.jar as one the maven dependency in ...
🌐
Reddit
reddit.com › r/intellijidea › junit not showing as an option for testing library when generating tests [solved]
r/IntelliJIDEA on Reddit: JUnit not showing as an option for testing library when generating tests [Solved]
July 25, 2023 - Problem: I was following a Spring Boot tutorial where they used JUnit tests to interact with a MySQL database and teach basics of JPA. When I tried to press Alt+Insert to generate the tests, in the create test window I could not find JUnit as an option in the testing library drop-down and could only see "Groovy Junit".
🌐
Baeldung
baeldung.com › home › maven › why maven doesn’t find junit tests to run
Why Maven Doesn’t Find JUnit Tests to Run | Baeldung
January 8, 2024 - The default access modifier in Java is package-private. This means that all classes created without additional access modifiers are visible only to the classes in the same package. Some IDEs have standard configurations so that, while creating tests, they will be marked as package-private. Also, the test method could have been marked as private by mistake. Until JUnit 4, Maven will only run the test classes that are marked as public. We should note, though, that this won’t be an issue with JUnit 5+. However, the actual test methods should always be marked as public.
Find elsewhere
🌐
Junit
docs.junit.org › 5.13.0-M2 › release-notes
JUnit 5 Release Notes
This milestone contains preliminary APIs for reporting issues encountered by test engines during test discovery. However, these are still under active development and not yet ready for general use. If you’re a maintainer of a test engine, please wait for the next milestone before adopting these new APIs.
🌐
Eclipse
bugs.eclipse.org › bugs › show_bug.cgi
551298 – [JUnit 5] Missing 'Run As... - JUnit Test' or 'No tests found with test runner JUnit5'
September 20, 2019 - Bugzilla – Bug 551298 [JUnit 5] Missing 'Run As... - JUnit Test' or 'No tests found with test runner JUnit5' Last modified: 2021-04-19 13:21:49 EDT ... This site is maintained for archival purposes only. Eclipse projects have transitioned to GitHub and Eclipse GitLab.
Top answer
1 of 9
153

According to the annotation (import org.junit.jupiter.api.Test), you are trying to run JUnit 5 tests with Maven. According to the documentation, you have to add this dependency:

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

Your version of Maven comes with a version of maven-surefire-plugin which does not support JUnit 5. You could update your Maven to the latest version. You could also set the version of the maven-surefire-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
    <version>2.22.0</version>
</plugin>

See the junit5-samples for this information.

See the Maven Surefire Plugin artifact in a Maven repository. At version 3.0.0-M3 as of 2019-01.

2 of 9
58

tl;dr

Add two dependencies to your project:

  • JUnit Jupiter (Aggregator)
  • Maven Surefire Plugin
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.9.1</version>
    <scope>test</scope>
</dependency>

… and:

<!-- https://maven.apache.org/surefire/maven-surefire-plugin/dependency-info.html -->
<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M7</version>
  <type>maven-plugin</type>
</dependency>

junit-jupiter — the simpler archetype for JUnit 5

The Answer by LaurentG seems to be correct, but a bit outdated.

As of JUnit 5.4, you can replace those multiple Maven artifacts:

  • junit
  • junit-jupiter-api
  • junit-jupiter-engine

…with a single artifact:

  • junit-jupiter

…to run JUnit 5 tests.

This artifact is an aggregate of other artifacts, a convenient wrapper to simplify your POM file. See this repository.

<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.9.1</version>
    <scope>test</scope>
</dependency>

This gives you all you need to write and run JUnit 5 Jupiter tests.

maven-surefire-plugin

You would also need the Surefire plugin as shown in that other Answer. Be sure to get the latest version, as Surefire has had some important fixes/enhancements recently.

See this list of dependency declarations for Maven, Buildr, Ivy, Grape, Grails, SBT, and Leiningen. To quote the Maven config:

<!-- https://maven.apache.org/surefire/maven-surefire-plugin/dependency-info.html -->
<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M7</version>
  <type>maven-plugin</type>
</dependency>

junit-vintage-engine for JUnit 3 & 4 tests

If you have old JUnit 3 or JUnit 4 legacy tests that you want to continue to run, add another dependency, junit-vintage-engine.

<!-- https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine -->
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.9.1</version>
    <scope>test</scope>
</dependency>
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-198059 › JUnit-not-found-in-module-for-JUnit5
JUnit not found in module for JUnit5 : IDEA-198059
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 206353249-Junit-Class-not-found-and-junit-framework-AssertionFailedError
Junit: Class not found and junit.framework.AssertionFailedError – IDEs Support (IntelliJ Platform) | JetBrains
March 25, 2004 - I now select the debug button and the Debug window appears and I receive the “Class not found” error message: If I select the package option and test all classes in the package I get a different result; in that a number of the test run successfully. However, where I try to Mock one of my interfaces I get a “junit.framework.AssertionFailedError: interface is not visible from class loader” message.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360004329680-IntelliJ-reporting-No-junit-jar-when-running-tests-after-upgrading-2019-2
IntelliJ reporting "No junit.jar" when running tests after upgrading 2019.2 – IDEs Support (IntelliJ Platform) | JetBrains
July 24, 2019 - The "No junit.jar" shows in the bottom-left of the screen. As for whether these run properly from the command line Maven, yes they do via "mvn clean verify". ... This is the very first line in the run tool window. Have you tried running tests by Maven from command line? ... This is the very first line in the run tool window. The problem is that it never gets that far. See picture above. No tests are run, and there is nothing in the "Test Results" of the Run tool window.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 2156437 › cannot-use-junit-testing-on-vscode
Cannot use JUNIT Testing on VSCode - Microsoft Q&A
February 11, 2025 - If you follow the above steps, but the error persists, please try to reinstall VS Code, reinstall JDK(uninstall it from Control Panel), and reinstall the extension then test again.
🌐
Baeldung
baeldung.com › home › testing › fixing the nosuchmethoderror junit error
Fixing the NoSuchMethodError JUnit Error | Baeldung
June 24, 2025 - Such problems usually occur when we have two different JUnit versions in our classpath. This situation may occur, for example, when the project’s JUnit version is different from the one that is used in a Maven or Gradle dependency.