Questions tagged [junit5]

Version 5 of the popular JUnit testing framework for the JVM. JUnit is a framework for writing repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.

JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage

JUnit 5 is the 5th generation of the popular JUnit testing framework for the JVM based on Java 8 and compatible with Java 9, 10, and 11.

The JUnit Platform serves as a foundation for launching testing frameworks on the JVM. It also defines the TestEngine API for developing a testing framework that runs on the platform. Furthermore, the platform provides a Console Launcher to launch the platform from the command line and build plugins for Gradle and Maven as well as a JUnit 4 based Runner for running any TestEngine on the platform.

JUnit Jupiter is the combination of the new programming model and extension model for writing tests and extensions in JUnit 5. The Jupiter sub-project provides a TestEngine for running Jupiter based tests on the platform.

JUnit Vintage provides a TestEngine for running JUnit 3 and JUnit 4 based tests on the platform.

JUnit 5 Resources

Frequently asked questions

Tags

  • Use the tag only for questions related to features provided by version 5 or migration to version 5.

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

  • Use the tag for general questions related to JUnit.

3531 questions
27
votes
2 answers

Junit 5 - How to pass in multiple null values for @CsvSource?

I am modifying a test method from single parameter to multiple: @ParameterizedTest @NullSource @ValueSource({"foo", "bar"..}) void shouldReturnFalse(String x) { assertThat(someMethod(x)).isFalse(); } @ParameterizedTest @CsvSource({ "null,…
夢のの夢
  • 5,054
  • 7
  • 33
  • 63
25
votes
5 answers

how to set the environment variables in junit 5 for test case

i am working on Junit5 . My java code uses the System.getenv("demoVar") to access environment variable . so how do i set up this environment variable in the jUnit5 test class , so that my code can access the value of this environment variable…
ashish choudhary
  • 291
  • 1
  • 3
  • 7
25
votes
3 answers

How to parameterize with String arrays in JUnit 5

I would like to write JUnit 5 parametrized test which takes string array (String[]) as a parameter: @ParameterizedTest @MethodSource("stringArrayProvider") void parseFirstAndSecondInt(String[] args) { Arguments arguments = new Arguments(args); …
Vít Kotačka
  • 1,472
  • 1
  • 15
  • 40
25
votes
7 answers

Tests not running through Maven?

When I run my test in Maven I get this: [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] [INFO] Results: [INFO] [INFO] Tests…
Ava
  • 502
  • 1
  • 6
  • 21
25
votes
2 answers

JUnit 5 vs TestNG

We were using JUnit 4, but we had some problems with test grouping. For integration tests we had problems with running order. We had migrated to TestNG in February 2016. Now we are starting a new independent module for our project and part of our…
Sergii
  • 7,044
  • 14
  • 58
  • 116
24
votes
1 answer

How to launch JUnit 5 (Platform) from the command line (without Maven/Gradle)?

I'd like to run a class containing JUnit 5 tests from the command line. Unfortunately, I have some outside dependencies that prevent me from using Maven, Gradle, or other build systems. In JUnit 4, I could accomplish this like java .:"lib/*"…
Rachel H
  • 241
  • 1
  • 2
  • 3
23
votes
8 answers

failed to resolve junit platform launcher 1.6.3 intellij

I am trying to run tests in Intellij which used to work earlier in spring boot 2.2.x. I recently upgraded to spring boot 2.3.9. When I try to run the test from Run Configurations, it doesn't run the test and throws the error: 'failed to resolve…
Humble Bee
  • 1,130
  • 2
  • 12
  • 19
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
23
votes
1 answer

How to make Spring's @Autowired to work in JUnit 5 extensions?

I have a Spring Boot application, and I am trying to use @Autowired in a JUnit 5 extension. However, I cannot get it to work. (The @Autowired field is null.) Can anybody help? Below is code that demonstrates the problem I'm having (the important…
23
votes
2 answers

JUnit test in nested Kotlin class not found when running gradle test

When I specify a test in a nested class in Kotlin as follows ... import org.junit.jupiter.api.* class ParentTest { @Nested class NestedTest { @Test fun NotFoundTest() {} } @Test fun FoundTest() {} } ... it…
Steven Jeuris
  • 18,274
  • 9
  • 70
  • 161
23
votes
3 answers

How to choose which JUnit5 Tags to execute with Maven

I have just upgraded my solution to use JUnit5. Now trying to create tags for my tests that have two tags: @Fast and @Slow. To start off I have used the below maven entry to configure which test to run with my default build. This means that when I…
Dan Ciborowski - MSFT
  • 6,807
  • 10
  • 53
  • 88
22
votes
3 answers

What causes a junit warning org.junit.platform.launcher.core.EngineDiscoveryOrchestrator lambda$logTestDescriptorExclusionReasons$7

I have a gradle-based java testing framework. After updating junit to 5.7.2 this warning started appearing for every test: Jul 21, 2021 10:23:45 AM org.junit.platform.launcher.core.EngineDiscoveryOrchestrator…
bohdan
  • 425
  • 1
  • 3
  • 8
22
votes
3 answers

How to fail a test after a timeout is exceeded in JUnit 5?

In JUnit 4 the "timeout" annotation parameter can be used to force a test to stop after the given amount of time: @Test(timeout=100) public void infinity() { while(true); } How can this be done in JUnit 5? Closely related to (and code taken…
A Jar of Clay
  • 5,622
  • 6
  • 25
  • 39
21
votes
3 answers

How to Parameterize beforeEach() in JUnit 5?

I am using JUnit 5 as my Test Runner. In the setup method, I have hardcoded 3 params (platformName, platformVersion, and deviceName). I have a test method that should test on various combinations... This means, when running my testLogin() test, it…
cpro
  • 225
  • 1
  • 2
  • 6
21
votes
3 answers

Mock Static Methods in JUnit5 using PowerMockito

Need help for Mocking Static methods using JUnit5 with PowerMockito framework. Powermock junit5 and mockito2.x not working RunnerTestSuiteChunker not found import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import…
chaitanya
  • 1,726
  • 2
  • 17
  • 13