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
44
votes
2 answers

@BeforeAll Method as non-static

I was able to implement a non-static setup method with @BeforeAll annotation. It seems to be working correctly as only gets call once. I am bit confuse as the documentation for @BeforeAll says the method has to be static. Please…
Meera
  • 455
  • 1
  • 4
  • 12
44
votes
2 answers

Are test suites considered deprecated in JUnit5?

I am trying to create test suites with JUnit5. After some research I was not able to conclude whether it is a supported feature or not. The official user guide only mentions suites with regard to backwards compatibility to JUnit 4. This is how it…
AscendingEagle
  • 771
  • 1
  • 7
  • 17
42
votes
5 answers

What is proper workaround for @BeforeAll in Kotlin

Currently the JUnit 5 API only allows @BeforeAll on a method that is static. So if I do something like this, it will not compile: @BeforeAll fun setup() { MockitoAnnotations.initMocks(this) mvc =…
Greg Konush
  • 572
  • 1
  • 5
  • 9
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
39
votes
5 answers

JUnit5 tag-specific gradle task

I use the following annotation to tag my integration tests: @Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Tag("integration-test") public @interface IntegrationTest { } This is the filter I use in…
Rahel Lüthy
  • 6,837
  • 3
  • 36
  • 51
38
votes
2 answers

Why JUnit 5 default access modifier changed to package-private

Why is the default access modifier in JUnit 5 package-private? Tests in JUnit 4 had to be public. What is the benefit of changing it to package-private?
wojtek1902
  • 503
  • 2
  • 10
  • 25
38
votes
1 answer

How to implement JUnit 4 parameterized tests in JUnit 5?

In JUnit 4 it was easy to test invariants across a bunch of classes by using the @Parameterized annotation. The key thing is that a collection of tests are being run against a single list of arguments. How to replicate this in JUnit 5, without using…
Sled
  • 18,541
  • 27
  • 119
  • 168
37
votes
6 answers

Junit5 mock a static method

I want to mock a static method in JUnit 5. But unfortunately, JUnit 5 doesn’t support Mockito. Is there another method to achieve the same other than reverting back to JUnit 4?
Priya
  • 1,096
  • 4
  • 15
  • 32
36
votes
4 answers

What is the equivalent of TestName rule in JUnit 5?

How can I get name of the test method in JUnit 5?
Mahozad
  • 18,032
  • 13
  • 118
  • 133
34
votes
1 answer

What is the difference between @ExtendWith(SpringExtension.class) and @ExtendWith(MockitoExtension.class)?

I was using @RunWith(MockitoJUnitRunner.class) for my junit test with mockito. But now I am working with spring-boot and JUnit 5. What's the difference between the two annotations ? Can I use only @ExtendWith(SpringExtension.class) to mock my…
user11705123
  • 503
  • 1
  • 5
  • 7
30
votes
9 answers

JUnit's @TestMethodOrder annotation not working

I'm having a problem with following integration test import org.junit.jupiter.api.Order; import org.junit.jupiter.api.TestMethodOrder; import…
toucheqt
  • 725
  • 2
  • 8
  • 15
29
votes
6 answers

JUnit test class order

I have a java app with maven. Junit for tests, with failsafe and surefire plugins. I have more than 2000 integration tests. To speed up the test running, I use failsafe jvmfork to run my tests parallel. I have some heavy test class, and they…
Sándor Juhos
  • 1,535
  • 1
  • 12
  • 19
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
29
votes
5 answers

JUnit 5 for Android testing

How to configure JUnit 5 for Android unit testing? I tried: testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0") But it doesn't work, when I run previous the simplest unit test: @Test public void addition_isCorrect() throws Exception { …
mac229
  • 4,319
  • 5
  • 18
  • 24
29
votes
2 answers

Why were JUnit Jupiter and JUnit Vintage separated When I Running TestCase in IntelliJ?

I saw that JUnit5 is released, and i applied in IntelliJ V2016.2.1 and run some testcase. so saw below screenshot. i have just two questions. Why were JUnit Jupiter and JUnit Vintage separated When I Running TestCase in IntelliJ? Can i Merge JUnit…
byrage
  • 534
  • 1
  • 6
  • 10