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
1 answer

Mock static void method with params using mockito and Junit5

I am trying to mock a static void method that take a parameter SMTPTools.send(Message) My deps: org.junit.jupiter junit-jupiter-engine 5.7.0
kwisatz
  • 1,266
  • 3
  • 16
  • 36
1
vote
1 answer

mocking the response for the method called inside the same class

Iam trying to write JUnit test case for the below class scenario. public class Class1{ @Autowired Class2 class2Obj; @Autowired Class3 class3Obj; public MyResponse searchTheDetails(String id){ GetDetails details; List names; id(id!=null){ …
user222
  • 587
  • 3
  • 10
  • 31
1
vote
1 answer

How run test suite JUnit5-based?

I want to create runner for my test classes that based on JUnit-5. In the first I tried to use with this construction. @RunWith(JUnitPlatform.class) @SelectClasses(UserAPITest.class) public class UserAPITestRunner { } But in doesn't work. If I…
robert0801
  • 140
  • 1
  • 12
1
vote
1 answer

Share database connection between JUnit 5 test classes

I have 6 JUnit classes into different test packages. I want to use application.properties file which is used by Spring framework to setup database connection. The problem is how to create database connection when first JUnit test is run and reuse it…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
1
vote
0 answers

How to test Methods from a SongServlet with JUnit 5

my Task ist to test a HttpServlet written in Java, which connects to a database and has the following methods implemented: doGet(), doPost(), doDelete(), doOptions() To test the functionality independently from the database connection I've…
Mahakala108
  • 85
  • 1
  • 11
1
vote
0 answers

How can I rerun only failed scenarios in the feature in Karate API?

I want to rerun failed scenarios in Karate. But I dont want to run whole scenarios in the feature file with call func. If feature has failed scenarios, I dont want to rerun failed step with "retry until". So, Is there a way to rerun only failed…
reyyanarik
  • 31
  • 2
1
vote
1 answer

Junit 5 doesn't see controllers URL when using @WebMvcTest - Mockito and Spring Boot

I created a test class for SystemAuthorityController, as i only need part of the context to be loaded. I've used @WebMvcTest annotation and I`ve specified which controller I want to test (I also tried with all controllers but that didn't work…
1
vote
2 answers

How to run both JUnit5 plus Spock 2.0 tests in Gradle project

I have a simple project and I want to be able to run both JUnit 5 unit tests plus Spock 2 functional tests. If I have the Spock dependencies in the below build.gradle commented out, my JUnit5 tests run and pass. However, if I un-comment the Spock…
1
vote
1 answer

Correcty parameterized test class fails in JUnit 5

I have problem about unit testing using JUnit 5, namely when I run test method with parameterized annotation it fails but everything is correct, I think. it is JUnit 5 code: @Test @ParameterizedTest @MethodSource("data") public void test(int e){ …
1
vote
0 answers

Unresolved dependency issue for JUnit tests with Gradle project in VS Code's Java Test Runnner

I cannot run my JUnit tests, which are part of a Gradle-based Java project, in VS Code using the Java Test Runner. I get a dependency resolution error when I run test: message: Unresolved dependency: org.junit:junit-bom:5.6.2; code: 0; resource:…
Tim Dean
  • 8,253
  • 2
  • 32
  • 59
1
vote
1 answer

How to make failsafe-plugin fail if @SpringBootTest could not load ApplicationContext

My @SpringBootTests are executed by maven-failsafe-plugin. That's working fine as long as the ApplicationContext could be loaded. If the ApplicationContext could NOT be loaded (e.g. because of a missing bean in the test) Spring is showing something…
Alex
  • 115
  • 1
  • 9
1
vote
0 answers

Setup method JUnit 5 TestSuite

I am trying to executes some tests using JUnit 5 Test Suite. Based on the documentation I found, I used @RunWith and @SelectPackages (from the dependency junit-platform-runner). Before I started the tests defined in the @SelectPackages, I wanted to…
Heru Salim
  • 11
  • 1
1
vote
0 answers

How to store mutable objects in ExtensionContext.Store

In most cases when I consider creating an extension, I run into the same problem: How to store mutable objects? Here is my problem: Let's consider that my extension provides a parameter resolver which provides a mutable object to the test. Let's say…
JojOatXGME
  • 3,023
  • 2
  • 25
  • 41
1
vote
0 answers

Android Studio - Test Business Logic in buildSrc (Gradle Kotlin DSL)

In my app, I 'd like to test the business logic I put in the buildSrc Code. The construction of my app is like that : + root +app + src + main + kotlin + res + test + kotlin + buildSrc + src +…
1
vote
2 answers

Spring Boot unit test constructor injection

I'm using Spring Boot to create a REST API and write some unit tests on my controllers. I know that the recommended manner to inject beans in spring is the constructor injection. But when i add the @SpringBootTest annotation to my test class, I can…
BARHOUMI
  • 204
  • 2
  • 12