Questions tagged [junit-jupiter]

JUnit Jupiter is the combination of the new programming model and extension model for writing tests and extensions in JUnit 5.

Use the tag for questions that are specific to JUnit Jupiter.

Use the tag for all other questions related to features provided by JUnit 5 or migration to JUnit 5.

JUnit 5 Resources

263 questions
481
votes
12 answers

JUnit 5: How to assert an exception is thrown?

Is there a better way to assert that a method throws an exception in JUnit 5? Currently, I have to use an @Rule in order to verify that my test throws an exception, but this doesn't work for the cases where I expect multiple methods to throw…
steventrouble
  • 6,641
  • 3
  • 16
  • 19
115
votes
19 answers

Junit 5 - No ParameterResolver registered for parameter

I can write up and execute Selenium script without any special test framework but I wanted to use Junit 5 (because we have dependency with other tools) and I have never seen such error org.junit.jupiter.api.extension.ParameterResolutionException…
Mike ASP
  • 2,013
  • 2
  • 17
  • 24
39
votes
21 answers

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests

I wan to implement a Junit 5 test into Gradle project. I tried this: Gradle configuration: plugins { id 'org.springframework.boot' version '2.5.5' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } group =…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
29
votes
1 answer

Java JUnit 5 annotations differences

I see there was introduced the new JUnit Jupiter according to JUnit 5 User Guide. JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage I am confused about the same-named annotations I use across the library. Is there any significant difference…
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
23
votes
5 answers

NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass

I have the test that leads to error. I tried to execute it in the IntelliJ Idea 2018.3.2. All jupiter and junit dependencies have version RELEASE The full text of error: Dec 26, 2018 1:17:17 AM org.junit.platform.launcher.core.DefaultLauncher…
Bizon4ik
  • 2,604
  • 4
  • 20
  • 46
16
votes
1 answer

What is junit-bom and junit platform for, and should I include them in gradle dependencies?

I'm reading Junit 5 User Guide. It leads me to a JUnit 5 Jupiter Gradle Sample, which is a simplest example of using Junit 5 with Gradle. In build.gradle file, there are 2 dependencies, junit-jupiter and junit-bom. And in test task, it also calls…
shen
  • 933
  • 10
  • 19
13
votes
5 answers

My PITEST won't run. Coverage generation minion exited abnormally. I need help to configure my pom.xml properly

When running mvn org.pitest:pitest-maven:mutationCoverage, I get the error as follows ( Environment: Windows 10, Maven 3.6.1, Java 11, junit-jupiter 5.4.1, pitest 1.4.7) [ERROR] Failed to execute goal org.pitest:pitest-maven:1.4.7:mutationCoverage…
Øyvind Roth
  • 217
  • 1
  • 2
  • 11
13
votes
1 answer

@DisplayName not working when tests executed through maven

JUnit5 tests results are not showing the specified @DisplayName when executed through maven. The same test suites show correctly assigned names when run under eclipse (right-click --> Run as... --> JUnit Test). This is an example of implemented…
pirxpilot
  • 131
  • 1
  • 5
13
votes
4 answers

JUnit 5 Disabled is ignored?

I'm using JUnit 5 with IntelliJ IDEA Community Edition version 2018. My code is simple: import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static…
Team
  • 587
  • 2
  • 9
  • 21
12
votes
3 answers

Mockito throws UnnecessaryStubbingException for stub defined in generic @BeforeEach setup method

I have a unit test class where my unit under test is dependent on another class. The dependency is mocked using Mockito and then setup with a generic stub that's run before every unit test, using JUnit's @BeforeEach annotation. See the below…
Martin Devillers
  • 17,293
  • 5
  • 46
  • 88
12
votes
3 answers

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/commons/util/ClassNamePatternFilterUtils

I want to configure Maven to run Junit 5 tests using these dependencies: org.junit.jupiter junit-jupiter-api 5.7.0-M1
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
10
votes
1 answer

Tests run under JUnit 4 but not JUnit 5 — Compiles clean, but 0 tests execute

Anyone can easily reproduce this problem in a couple minutes. Basic Maven quickstart project With IntelliJ 2018.3 and Maven 3.6.0, I create a brand new project using the Maven archetype maven-archetype-quickstart version 1.4. Java 11 In the POM…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
9
votes
3 answers

java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute

I'm trying to run the following example unit test case class ExampleUnitTest { @Test fun addition_is_Correct() { assertEquals(4, (2 + 2).toLong()) } } but I get the following exception Exception in thread "main"…
kokilayaa
  • 579
  • 4
  • 7
  • 19
8
votes
4 answers

How to Mock System.getenv() with JUnit5

I want to mock the System.getenv() method. I found only solutions for JUnit4 and PowerMockito. I use the following dependency: org.mockito mockito-junit-jupiter
GreenJenks
  • 111
  • 1
  • 9
8
votes
2 answers

Spring REST docs: How to migrate Rule to JUnit 5

I migrated my Spring tests to JUnit 5, and they work fine. However, I don't know how to migrate @Rule public JUnitRestDocumentation restDocumentation = .... Any hint is appreciated.
Juergen Zimmermann
  • 2,084
  • 7
  • 29
  • 43
1
2 3
17 18