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

In JUnit 5 test, how can I test a number whether it is positve or negative or a mix of both?

I'm new to JUnit testing. I've tried using conditions, but it doesn't seem to work using assertEquals. For example, assertEquals(1 > 0, 10) which gives me a failed test. Is there another way of doing it? Thanks.
1
vote
1 answer

I need help setup a controller test using Spring, Junit 5, Mockito, REST-Assured, and Lombok

I need help setting up a controller test using Spring, Junit 5, Mockito, REST-Assured, and Lombok. Have I missed a configuration step? When I try to run a test, I am getting: java.lang.NoSuchMethodError:…
William Jones
  • 61
  • 1
  • 7
1
vote
2 answers

How to make Junit test in spring boot

I want to test the behaviour of my rest controller methods, using Mockito.test. I have the following controller class @RestController @RequestMapping("/project/image") public class ImageController { @Autowired ImgService…
Fadi
  • 203
  • 4
  • 14
1
vote
1 answer

Spring Boot integration test can't find configuration

I have a simple Spring Boot application, consisting only of this class: @SpringBootApplication public class TestApplication { public static void main(String[] args) { SpringApplication.run(TestApplication.class, args); } } I want…
Mark
  • 4,970
  • 5
  • 42
  • 66
1
vote
0 answers

Excluding Time Duration of @BeforeEach and @AfterEach in JUnit5

I Noticed, that JUnit5 @BeforeEach and @AfterEach is included into Test time duration. I am writing a Performance test, which results is presented on Jenkins Performance report, which takes data from JUnit5 results and draws a Graph, but problem is…
1
vote
1 answer

Junit 5 and Mockito 3: UnnecessaryStubbingException not thrown when injecting @Mock's through constructor

Looking at the two test classes below I assume the same behavior from them: to have an UnnecessaryStubbingException thrown. However MyTest2 does not. The MockitoExtension class should have strictness set to strict stubs by default. I can't seem to…
Niklas Larsson
  • 99
  • 1
  • 11
1
vote
0 answers

Error with writing Mockito Unit test with @Spy for Groovy class which extends an abstract class

I am facing an issue when run Mockito Unit test with @Spy for Groovy class which extends an abstract class. This error does not occur if I remove abstract or create a parent class as a regular Java class. What might be the issue? abstract class…
1
vote
0 answers

Run JUnit 5 Test Suite loading Spring context

I'm facing problems when running a Test Suite of JUnit 5 Jupiter with Spring. I'm using latest version of Spring (5.2.8-RELEASE) (not spring-boot) and latest version of JUnit Jupiter (5.7.0). Here is my Test Suite code: package…
Marc Gil Sendra
  • 819
  • 2
  • 9
  • 22
1
vote
0 answers

SoapuUI.setSoapUICore causing Junit threads to end

I have a Maven/Junit test project that I'm running in concurrent mode. Each test case calls a web service using the SoapUI API: public void makeWebServiceCall(String testCaseName) { SoapUI.setSoapUICore( new StandaloneSoapUICore(true) ); …
1
vote
1 answer

Junit testing- java.lang.AssertionError: Status Expected:<200> but was:<403>

I know this kind of questions has been asked before and I tried many of the answers given in there and none is doing good, So can someone please help me out in this for getting proper solution Its my Controller…
groot
  • 57
  • 3
  • 12
1
vote
0 answers

Using mockito. Trying to verify if my method was used

I use Mockito and JUnit 5. I have a small program that counts distinct characters in a string. I have a cache in the form of a Map and the result is picked from the cache if the input string had been processed before. My goal is to write a test…
IceTeaGreen
  • 133
  • 12
1
vote
0 answers

Consumer Driven Contracts with Junit 5

How to properly annotate BaseTests for CDC with spring-cloud-contract? I'm using currently @RunWith(SpringRunner.class) @SpringBootTest(classes = {WithoutDbConfig.class, SomeController.class}) public abstract class BaseControllerTest { as it is…
tillias
  • 1,035
  • 2
  • 12
  • 30
1
vote
1 answer

How to pass argument to extension class constructor in JUnit5

I have a problem to pass argument from test class to its extension class constructor. Problem occurred during migration from JUnit4 to JUnit5. (For JUnit4 worked fine) In JUnit4 test class looked like: public class TestClass{ @Rule …
1
vote
1 answer

How to create mock email service in Java?

I am writing a small testing library with different mock services such as HTTP, SFTP, Buckets, Email. I have a mind block when it comes to Email Mock service. I find a Apace James docs and an article but I don't see how I can adapt it to my…
Dmytro Chasovskyi
  • 3,209
  • 4
  • 40
  • 82
1
vote
1 answer

Selenium-Jupiter generic webdriver settings not applied

I want to use Selenium-Jupiter in my Spring Boot Project but my requirement is to switch the WebDriver implementation at runtime - based on the execution environment - using one common base class for all tests. I already checked this post and this…