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
0 answers

How to create a @MockBean with pre-defined answers?

I have a MockBean in my test: @MockBean(SomeClient.class) SomeClient client; I'm starting up a spring-boot test: @ExtendWith(SpringExtension.class) @ActiveProfiles("test") @SpringBootTest(properties = { "spring.jpa.hibernate.ddl-auto=create-drop"…
ScrappyDev
  • 2,307
  • 8
  • 40
  • 60
1
vote
2 answers

How to create a mock object of org.springframework.http.codec.multipart.FilePart for Junit

I am trying to write unit test case for a function which takes a parameter of type "org.springframework.http.codec.multipart.FilePart" as an input. However I am not able to figure out how to create a mock object of the class implementing above…
Paras
  • 3,191
  • 6
  • 41
  • 77
1
vote
1 answer

Tests not running with Junit 5 and Maven

I am trying to run Jacoco test coverage for my project. When I use the command mvn clean package from the terminal, the test cases won't run. But when I run the same tests using IntelliJ, everything works fine. My maven version is 3.6.3. These are…
Andy
  • 5,433
  • 6
  • 31
  • 38
1
vote
2 answers

How to use JUnit5 Parametrized Test CSV file source?

I am trying to run a parametrized test from CSV-file. It is working if I use just CSVSource like that: @ParameterizedTest @CsvSource({ "a,A", "b,B" }) void csvSourceTest(String input, String expected) { String actualValue = input.toUpperCase(); …
user8444746
1
vote
1 answer

Maven Surefire not running JUnit 5 tests

I've been trying to run JUnit 5 tests with Maven Surefire. However, it doesn't seem like Surefire is running any tests at all, even though I do have some, and in the default directory, too. This is the console output I'm getting:…
marceggers
  • 13
  • 1
  • 4
1
vote
1 answer

How to assert if a lambda has been called

I'm currently working with lambda (Consumer or Function) as a parameter of my methods. And I'm wondering what is the best way to assert if the lambda has been executed. I've found 2 solution and I wonder which one is the better or if something else…
Ruokki
  • 869
  • 1
  • 7
  • 24
1
vote
0 answers

@EnableBatchProcessing breaks other JPA junit tests

I have a microservice where multiple @DataJpaIntegrationTest junit tests are present. As soon as I am adding @EnableBatchProcessing , all junits annotated with @DataJpaIntegrationTest are failing. Problem seem to be as no transaction is happening. I…
user2800089
  • 2,015
  • 6
  • 26
  • 47
1
vote
0 answers

Remote Test Execution with JUnit 5 (vs JUnit 4)

Some time ago, I implemented a remote test execution feature on JUnit 4 for the z2-environment (a Java server development and execution environment for large Java applications). Possibly similar to the Teleporter Rule of Apache Sling (for which I…
gnomie
  • 439
  • 5
  • 16
1
vote
0 answers

@SpringBootTest classes run in same thread although configured concurrently

I have several test classes that are annotated with @SpringBootTest and also AutoConfigureMockMvc. They look like this: @SpringBootTest @AutoConfigureMockMvc class ThymeleafFormatIT { @Autowired lateinit var mvc: MockMvc @Test fun…
Joshua
  • 2,932
  • 2
  • 24
  • 40
1
vote
1 answer

How to force specific test class to be executed in a separate jvm?

In order to avoid race condition and isolate usage of a shared resource, I want to run some specific tests in a forked jvm. How should I do it with Junit 5 & Gradle?
andreoss
  • 1,570
  • 1
  • 10
  • 25
1
vote
1 answer

JUnit Test coverage when there exists a JNI API call

I am writing JUnit test cases. I have a class that contains APIs which call JNI APIs. public class Test { public native int getId_native(); public void doSomething() { // do init int id = getId_native(); // Get name…
Androider
  • 23
  • 4
1
vote
1 answer

jsonPath cast issue in Junit5 spring boot with MockMVC

I have the below test case with imports as import org.springframework.http.MediaType; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; import static…
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
1
vote
2 answers

Run All JUnit Tests VSCode

I've been able to add JUnit 5 to VSCode and run tests on single files, but I'd like to be able to use the 'Run all tests' button in the test explorer pane so that I can get all tests to run at once. However, i'm encountering a problem where when I…
テッド
  • 776
  • 9
  • 21
1
vote
0 answers

Github Classroom Autograding

I created an assignment in Github classroom and added test. The test is running when student commits and in actions tab shows passed or not.But in Github Classroom page as a teacher I cant see this.Doesn`t matter what I change I always get an "No…
Khagan
  • 21
  • 3
1
vote
1 answer

APPLICATION FAILED TO START because method required a single bean, but 4 were found JUnit 5 + Spring Kafka

Writing the JUnit test to test the controller method, mocking the service methods using Mockito. service class @Service public record ProductProducer(ReplyingKafkaTemplate _replyTemplate, …
San Jaisy
  • 15,327
  • 34
  • 171
  • 290