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
1
vote
4 answers

How to test repository with junit5 and testcontainers?

I have a sample project in which I experiment with different technologies. I have the following setup: Spring Boot 2.3.4.RELEASE Flyway 7.0.1 Testcontainers 1.15.0-rc2 Junit 5.7.0 How can I test the Repository layer with…
1
vote
1 answer

Test spring boot controllers with JUnit5+Spring Security

I have a spring boot application and want to write integration tests for controllers. It is my SecurityConfig: @Configuration @EnableWebSecurity @RequiredArgsConstructor public class SecurityConfig extends WebSecurityConfigurerAdapter { private…
1
vote
1 answer

How to put the vertx @Rule about RunTestOnContext in the vertx-junit5 way?

I would like to know if it is possible migrate this kind of rule(junit) to vertx-junit5 way. The original example is the RunOnContextTest.java from the public vertx-example repository in github. Here is the…
mononoke83
  • 342
  • 2
  • 16
1
vote
1 answer

Mockito Junit 5 Throw checked exception not working

I am trying to throw SQLException during a method call. But the exception is not thrown for some reason. Error message org.opentest4j.AssertionFailedError: Expected java.sql.SQLException to be thrown, but nothing was thrown. at…
Andy
  • 5,433
  • 6
  • 31
  • 38
1
vote
1 answer

Start and shutdown Spring application context in a unit test

What's the recommended way to start and gracefully shutdown a Spring application within a unit test? I am aware of the SpringExtension for JUnit5, but that starts and stops the Spring context before/after the test method execution. I would like to…
Oliver
  • 353
  • 1
  • 4
  • 16
1
vote
1 answer

AssertJ usingRecursiveComparison fails when a class field is a collection

class Person { private List phones; } class Phone { private String number; } assertThat(result).usingRecursiveComparison() .ignoringCollectionOrder() .isEqualTo(expectedPerson); The expectedPerson has the same number of…
LunaticJape
  • 1,446
  • 4
  • 21
  • 39
1
vote
0 answers

Questions regarding jUnit5 dynamic tests parallelism control

Currently I am writing some dynamic tests in Junit5 and I have questions regarding parallelism. Is it possible to run dynamic tests in parallel, while factory methods are being executed sequentially? And opposite question: is it possible to run…
Ign
  • 31
  • 2
1
vote
0 answers

How do I randomize all tests when running them from a Launcher instance?

I have a few test classes annotated with @TestMethodOrder; they are performed in a random order, but when I discover and execute them from a Launcher instance, they run in the order that they were discovered (ie TestClassA has its tests randomized,…
1
vote
1 answer

JUnit5: Surefire plugin runs JUnit4 tests twice

I have both JUnit4 and JUnit5 tests in my project. The problem is that when I run mvn clean install the JUnit4 tests are run twice (JUnit5 tests run fine and once only). I have the following surefire-plugin configuration (showing only relevant…
Harry
  • 321
  • 4
  • 13
1
vote
1 answer

Test class can only have one constructor error while running JUnit 5 tests

Can anyone explain why am i getting this error while running below code ? get same error with other annotations also (e.g. @MethodSource , @CsvSource) class TestRunningOnJUnit5 { @ParameterizedTest @CsvSource("test,TEST", "tEst,TEST",…
Shah
  • 553
  • 5
  • 12
1
vote
2 answers

MockMVC adds additional quotes with string in request param with post request

MockMvc adds quotes at the ends of string when passed in param() in request builder like following // initialization of mockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); ObjectNode tweets = ((ObjectNode)…
It's K
  • 177
  • 3
  • 15
1
vote
0 answers

How do I find junit.platform.console.ConsoleLauncher

My project must run java test in terminal for cicd, in fact, the project is C/C++ and I am coding Java interfaces on demo stage. I used apt-get install junit5 to install junit on my system, and the default path is in /usr/share/java: .rw-r--r-- root…
user7633138
1
vote
1 answer

How to publish pact verification result to pact broker in gradle?

I have a service built with spring boot using gradle (gradle file at the bottom if needed) and Junit5. Many of the questions on stackoverflow are for maven and Junit4 and I have trouble translating the answers. My pact producer test runs and tests…
findusl
  • 2,454
  • 8
  • 32
  • 51
1
vote
0 answers

Failed to run SpringBootTest in jhipster gradlew by vscode (java.lang.IllegalStateException: Failed to load ApplicationContext)

I create a fresh jhipster project with gradle. I run ./gradlew test and it passes, but when I click "Run Test" button in vscode, it throws Error Stack java.lang.IllegalStateException: Failed to load ApplicationContext at…
Jeff Chung
  • 176
  • 3
  • 13
1
vote
1 answer

Expecting exception during MockMVC.perform in JUnit5

This may be a repeated question. But I have gone through some 10-15 related posts and associated responses which have not resolved my issue. The issue that I am facing is as here below I have a SpringRest controller class with custom…
Ram
  • 327
  • 1
  • 4
  • 18