Questions tagged [junit5-extension-model]

Use this tag only for JUnit 5 or any versions thereafter and when related to the Extension Model created for JUnit 5. AKA JUnit Jupiter Extension Model, JUnit labmda Extension Model.

The JUnit 5 Extension Model replaces the @Rule and @ClassRule with a new model for extending test.

References:

JUnit 5 User Guide - Extension Model

75 questions
4
votes
1 answer

How to create custom JUnit5 Extensions

Is it possible to create a custom extension like I could've created a @Rule in JUnit4? public class MockMetadataServiceRule extends ExternalResource { @Override protected void before() throws Throwable { //some setup } …
LazerBanana
  • 6,865
  • 3
  • 28
  • 47
3
votes
0 answers

Annotate a full class with an extension, while intercepting all the tests and invoking them multiple times

TL;DR Is there any way we could annotate a full class with an extension, while at the same time being able to intercept all the tests and invoke them multiple times? We are trying to update one of our projects from Junit4 to Junit5 (find the link…
shermosa
  • 31
  • 2
3
votes
3 answers

Junit 5.5.1 and 5.5.2 suddenly failing to run tests: "Process finished with exit code -1"; 5.6.0-RC1 is missing a class

I added Junit 5.5.1 to a project that otherwise uses 4.11. I've written tests that, until today, were running just fine. Today all the tests were failing with exit code -1 even before any of the test class was executed. I'm not aware of any…
Tom Rossen
  • 61
  • 1
  • 5
3
votes
2 answers

How to access test method annotations from a TestExecutionListener

I'm trying to port Test Management For Jira JUnit Integration to JUnit5. This module generates a JSON report of the test run and associates the results with Jira tickets by using annotations on the test methods, example. From the…
user11481216
3
votes
1 answer

Override Mockito statements in local function doesn't work with PER CLASS mode?

I'm new to JUnit5 and I noticed something weird happening. Let's see it with an example, I have a source class named A class A { someDownStreamService service; void printer() { int getData = service.getIntegerData(); …
3
votes
1 answer

Executing extension before SpringExtension

I'm trying to implement integration testing in my app and have test class like…
3
votes
1 answer

Set parameter to JUnit5 extension

I wonder how to configure an extension by a test. Scenario: The test provides a value that should be used inside the extension. Current Solution: The value is defined as field inside the test and used by the extension thru scanning all declared…
R4FT3R
  • 69
  • 1
  • 8
2
votes
0 answers

Clarification needed in JUnit5 TestInfo's getTestClass()

fellow Coders. The getTestClass() of JUnit5's TestInfo returns an 'Optional'. This has me wondering a scenario that would return an Optional.empty(). (Link to TestInfo documentation:…
divad
  • 75
  • 1
  • 8
2
votes
1 answer

Catching exception thrown by Junit5 extension, can it be done?

Background: I have two extensions. One that creates some required test data before any test starts and another one that saves unique identifiers of all failed tests, so that they can be retried later. I've noticed that if the first extension throws…
2
votes
0 answers

Is there a recommended way to reuse collections of JUnit 5 extensions?

JUnit 5 seems to heavily recommend not using inheritance to share test logic and instead says to use Extensions. So we're refactoring things into extensions. Something I frequently see is a large number of tests programmatically adding the same…
Hakanai
  • 12,010
  • 10
  • 62
  • 132
2
votes
1 answer

Can JUnit 5 actually inject extension instances?

The documentation for @RegisterExtension mentions something about injection of the instance: the extension will be registered after the test class has been instantiated and after all TestInstancePostProcessors have been given a chance to…
Hakanai
  • 12,010
  • 10
  • 62
  • 132
2
votes
1 answer

Passing an external property to JUnit's extension class

My Spring Boot project uses JUnit 5. I'd like to setup an integration test which requires a local SMTP server to be started, so I implemented a custom extension: public class SmtpServerExtension implements BeforeAllCallback, AfterAllCallback { …
Robert Strauch
  • 12,055
  • 24
  • 120
  • 192
2
votes
0 answers

Powermock or PowerMockito with JUnit 5

Is somebody able to direct me to one solid piece of documentation that outlines how to integrate JUnit 5 with Powermock framework, specifically the PowerMockito class? I see many people having issue with this on stack overflow and multiple other…
2
votes
2 answers

junit5 + weld + mockito extension, how to inject @Context object

This is my REST resource: @Context HttpServletRequest webRequest; @Override public DomainConfig get() { return configDelegate.get(webRequest.getHeader("Origin")); } I've built my unit test with Junit 5 + Weld / Mockito…
Fabrizio Stellato
  • 1,727
  • 21
  • 52
2
votes
1 answer

Is there a way to get a reference to the Spring application context inside a TestExecutionListener?

I'm running end to end tests with JUnit and Selenium, the application under test is often misconfigured and I want to be able to run a setup once before all tests. How can I get a reference to the application context of my tests from within a…
asenec4
  • 367
  • 3
  • 16