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 can I migrate a @Rule of Testname from junit4 to the TestInfo in Junit 5 from an abstract java class?

In my Abstract class I have this code line : @Rule public final TestName testName = new TestName(); That is used in some tests to pass the specific method the name, for example: @Test public void assertApiUp() { …
mononoke83
  • 342
  • 2
  • 16
1
vote
1 answer

Why is Eclipse trying to use JUnit5 when it should use JUnit4?

I'm just going through a tutorial which is a Maven project in Eclipse, and it should run some tests using JUnit4, so I have put this dependency in the POM: junit junit
flytzonen
  • 13
  • 2
1
vote
1 answer

Cucumber UndefinedStepException when running tests with external runner based on JUnit5 platform

I've written a very simple wrapper around the JUnit5 platform to run tests filtered by my external logics (which feeds path, packageIds, filterFilePath - handling of these was replaced by constant values in code samples to simplify the code…
1
vote
1 answer

How can I filter skipped tests during discovery in junit jupiter?

We have an internal tool that distributes hundreds of thousands of tests to cloud workers. I've written a tool that discovers all the tests that need to be run using a LauncherDiscoverRequest, and everything is working. However, some of our tests…
pburka
  • 1,434
  • 9
  • 12
1
vote
2 answers

Possible to Skip Junit tests only in Jenkins?

Currently our companies Jenkins deploy process isn't set up to read external property files for testing. I would still like to write and run tests locally and then have tests be skipped when pushed to github (where a jenkins process gets kicked of…
1
vote
1 answer

How to test when Superclass method is called?

I tried to test below class but got "org.mockito.exceptions.base.MockitoException: Only void methods can doNothing()!" and when i tried for Mocking i got nullpointerException. @Configuration @Profile("cloud") public class PsqlConfiguration extends…
1
vote
1 answer

Is there any way in JUnit > 5.6.0 to load context before class execution condition evaluation?

My goal is to execute tests in test class only when some spring property declared in application-foo.properties is equal to some constant. I've tried to reach this by writing my own ExecutionCondition with annotation using it, and when I use it on…
CalmTechie
  • 71
  • 1
  • 7
1
vote
1 answer

Is Junit5's TestReporter thread-safe?

Is the below piece of code fine where two threads may end up modifying the TestReporter instance at the same time? @Test public void someTest(TestReporter testReporter) { // do some stuff CompletableFuture.allOf( …
6harat
  • 542
  • 6
  • 18
1
vote
0 answers

Is there a way to enforce execution order of test classes in Junit4(5)

I am writing integration tests in a SpringBootApp with Junit5. It is a must for me to follow a execution order of REST Api calls. In one test class it is ok to use @TestMethodOrder from jUnit5 or another approach for test execution ordering in a…
1
vote
0 answers

Programmatically run only the unit tests that compile?

I develop an application to grade student code. Their grade should depend on the number of unit tests (that I provide) that pass (using their code). I understand that I can launch unit tests programmatically using the JUnit Launcher. That’s great.…
Olivier Cailloux
  • 977
  • 9
  • 24
1
vote
2 answers

Unit testing Kafka-streams with TopologyTestDriver and Micronaut

When I try to run a basic unit test I get the following error: java.lang.IllegalArgumentException: Unknown topic: streams-wordcount-output at org.apache.kafka.streams.TopologyTestDriver.getRecordsQueue(TopologyTestDriver.java:705) at…
Andras Hatvani
  • 4,346
  • 4
  • 29
  • 45
1
vote
4 answers

How to mock RestTemplate in Springboot app

This question has already been asked. The accepted answer doesn't work for me. Here is my code:- My service is here: @Service public class PlantService { @Autowired RestTemplate restTemplate; static String url =…
masiboo
  • 4,537
  • 9
  • 75
  • 136
1
vote
3 answers

Junit test 5 (Exception)

I am doing a Junit test and in one of the tests I have problems but I don't understand why. You do not have to allow more objects to be added to the list at any given time, that the size of the list is greater than 5, in short, if I add the sixth…
1
vote
0 answers

Allure annotation @Step does not added into generated report

When running tests, a report is generated, but the steps are not displayed and there is no information about the execution, in the "Execution" section it is written: "No information about test execution is available." I think I have an error in…
Ivan
  • 11
  • 2
1
vote
0 answers

Mockito Junit jupiter api not resolving the parameter JsonObject

Inorder to get multiple values for test case from JSON file, added the annotation @jsonfilesource and passed JSONObject as parameter to the method in Mockito framework. But I am getting below…
priya
  • 21
  • 2
1 2 3
99
100