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 do Pit Tests (Mutation tests) with Junit5 in InteliJ

I tried to set up Pit Tests in inteliJ-idea but unfortunately i am not sure how to set it up, in the end i did them in eclipse and it is much easier to navigate, but i would like to know how to set them up on inteliJ-idea. It is kinda stupid to…
1
vote
1 answer

Testing a FXGL game

I'm programming a simple game in Java FXGL. I'm very new to Java FX and FXGL. I'd like to test my game with JUnit5, but I can't get it to work... The problem: When I launch my tests, the FXGL properties aren't initialized yet. I would be very happy…
testgoofy
  • 33
  • 4
1
vote
2 answers

Spring @Value injection conversion not working in @SpringJUnitConfig test

I couldn't find a way to make the automatic value conversion when injecting @Value work when using @SpringJUnitConfig test. For example, for the given code: @SpringBootApplication class DemoApplication fun main(args: Array) { …
Yonatan
  • 2,543
  • 2
  • 19
  • 20
1
vote
1 answer

How to get JUnit tests annotated with @Tag to be executed in suite that has @IncludeTags?

I have the following code: Test class: @Tag("foo") class SomeIT { @Test public void testSomeStuff() { ... } } Suite class: @RunWith(JUnitPlatform.class) @IncludeTags({"foo"}) //@SelectPackages("org.foo") public class…
carlspring
  • 31,231
  • 29
  • 115
  • 197
1
vote
1 answer

How to create a data driven test in Spock2 considering all values of an enum source (basically as an alternative to Junit5 @EnumSource)?

I want to test a particular system behavior considering all the values (and at times excluding a few) from an enum. This can be easily achieved in Junit5 using the @EnumSource annotation. Is there any alternative in Spock2 (or any simple…
Saikat
  • 14,222
  • 20
  • 104
  • 125
1
vote
1 answer

Org.Junit is unresolved in Spring boot version 2.3

I created a SPRING BOOT application version 2.3.2 and when I try to write unit test with JUNIT 5. Unit test class in STS IDE shows org.junit is unresolved. Here is my depedency from build.gradle dependencies { compile…
Giri
  • 103
  • 2
  • 16
1
vote
1 answer

JUnit 5 test class attributes are null before each test

I have a JUnit 5 test class with a non static String attribute (value). The test class has 2 test methods, which are executed in a defined order (for question order does not matter). The first executed test method sets the String attribute to…
Elmar Brauch
  • 1,286
  • 6
  • 20
1
vote
1 answer

How to write description in Junit?

I am using Test Driven Development approach for coding and testing various modules. What I want to do? : I want to write some description to all my test cases so it could easily be readable for anyone. How I am writing description right…
Zahid Khan
  • 2,130
  • 2
  • 18
  • 31
1
vote
1 answer

Unable to run tests after migrating to junit5

I'm running tests on android using gradle and we're migrating our framework to junit5 to take advantage of some of it's tagging and filtering capabilities. I've created the dependencies in my build.gradle files and I'm able to get it to build and…
1
vote
1 answer

junit5 throws an unwanted exception

I am about to write unit testcase with junit5 for my spring integration project. But when i am running a sample testcase, i am getting an exception. the below given code is my sample testcase, @SpringBootTest class IntegrationUtilsTest { @Test …
Sanal M
  • 187
  • 4
  • 17
1
vote
1 answer

Why is ProducerTemplate's method sendBody not returning in integration test?

I want to test one Apache Camel route in a Spring Boot integration test, but the integration test doens't finish. ProducerTemplate#sendBody doesn't return. Spring Boot application @SpringBootApplication public class TestApplication { public…
dur
  • 15,689
  • 25
  • 79
  • 125
1
vote
1 answer

How to combine ExtentReports for multiple JUnit5 test classes into one HTML file?

I'm using ExtentReports (version 5.0.5) with JUnit 5. Here is my BaseTest class snippet. public class BaseTest { protected static ExtentReports extent; protected ExtentTest test; protected ExtentTest node; @BeforeAll static void…
Vladimir
  • 630
  • 3
  • 12
  • 26
1
vote
3 answers

JUnit5/AssertJ create Log entry on assertion

I need to provide some kind activity protocol for unit tests to provide additional tracability to non technical actors... So what i need is that every assertion also create a custom log entry. Is there any way in AssertJ to achieve this? maybe some…
markus
  • 31
  • 1
  • 3
1
vote
1 answer

How to test a private function in kotlin?

I have two objects remote model and domain model Remote model data class InstanceRemoteModel ( val id: String, val containers: List, val operations: List ) data class ContainerRemoteModel ( val id: String, …
LivBanana
  • 361
  • 2
  • 9
1
vote
1 answer

How to test if a variable exists using JUnit 5?

I would like to test to see if a variable exists in JUnit testing. I have a class called animal which is an abstract class. public abstract class Animal { private final int age; private final int speed; public Animal (int age,int…
mohelt
  • 55
  • 2
  • 6