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

how to add custom info to junit5 HTML test report?

Is it possible to add (log) custom information in HTML report for the passed test in Junit5 ? I tried to use org.junit.jupiter.api.TestReporter from https://junit.org/junit5/docs/current/user-guide/#writing-tests-dependency-injection but the…
Bartosz Bilicki
  • 12,599
  • 13
  • 71
  • 113
2
votes
1 answer

How execute code after each dynamic test?

There is a test: package com.cdek.qa_auto.config; import com.cdek.qa_auto.utils.CdekJUnitListener; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import…
1
vote
1 answer

How to suppress execution of @BeforeEach and @AfterEach methods of outer class between tests of inner (nested) class

The following sample test generates the output as printed below. Sample test: import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.RepeatedTest; import…
0x5F3759DF
  • 283
  • 3
  • 9
1
vote
1 answer

How to programmatically register extensions in Junit5

Say, a test needs a parameter that is only known when the tests are about to run. @ExtendWith(MyParameterExtension.class) public class Test { protected final MyParameter p; public Test(MyParameter p) {} @Test public void test() {…
Pawel Veselov
  • 3,996
  • 7
  • 44
  • 62
1
vote
0 answers

JUnit5 - Execute first parameterized test in parallel then going sequential

I want to implement the following scenario. Starting with a list of arguments passed into a first test in my class that should run in parallel, i then want to switch to sequential behavior for very single argument passed to the first test. Given the…
Bernado
  • 548
  • 1
  • 6
  • 18
1
vote
1 answer

Junit 5 extension - how to access testDescriptor

I am writing an extension for a test using @ParameterizedTest. My test looks like: @ParameterizedTest @ValueSource(strings={"string1", "string2"}) public void test1(String name){ System.out.println(name); } In the extensions, how do I get the…
1
vote
1 answer

How to inject Mock after Mockito.Mock()

I've an abstract class with so many methods with business logic. While writing Junits I'm testing abstract class by creating its Mock with Calls to real methods. In my Junit, I don't want to create a concrete class to test abstract class method,…
ThrowableException
  • 1,168
  • 1
  • 8
  • 29
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
1 answer

How to put the vertx @Rule about RunTestOnContext in the vertx-junit5 way?

I would like to know if it is possible migrate this kind of rule(junit) to vertx-junit5 way. The original example is the RunOnContextTest.java from the public vertx-example repository in github. Here is the…
mononoke83
  • 342
  • 2
  • 16
1
vote
1 answer

How to get repetition count in a junit 5 extension

I try to write my own JUnit 5 extension, providing some simple information about test duration. I also want to print out the repetition information but how can I access these informations in the extension? Are there any simple ways instead of…
1
vote
1 answer

JUnit5 afterAll callback fires at the end of each test class and not after all tests

I have 15 JUnit5 classes with tests. When I run them all from maven, the afterAll() is executed 15 times which causes 15 notifications to a Slack Webhook. Is there anything else I need to only send one notification? public class…
Ilyas Patel
  • 400
  • 2
  • 11
  • 27
1
vote
0 answers

How to programmatically Autowire a bean based on Qualifier Annotation

In Junit5, when using Extensions, we can run BeforeAll and AfterAll methods, and I'm trying to change behaviour of the test using Annotations. However, I'm using these annotations as @Qualifiers as well for bean initialisation, and want to be able…
nishantvas
  • 184
  • 3
  • 16
1
vote
1 answer

Can an executing JUnit 5 test register additional tests?

I would like to write a JUnit 5 extension that can register additional dynamic tests during execution. These would ideally appear as children of the executing test method or class. I've looked at the ExecutionContext provided to extension callback…
Fr Jeremy Krieg
  • 482
  • 5
  • 13
1
vote
1 answer

TempDirectory extension: is there a replacement for createInCustomDirectory() methods?

There used to be createInCustomDirectory() methods in TempDirectory extension class in JUnit 5.4.0-M1 (see docs). The main use case for those methods was to change tmp dir used by the extension. In the final release (5.4.0) TempDirectory extension…
Andrei Pechkurov
  • 438
  • 4
  • 10
1
vote
1 answer

How to inject Environment into ExecutionCondition

I'm writing unit tests and trying to use ExecutionCondition for enabling the test only when specific profile activated exclusively. I created my ExecutionCondition. class EnabledWithH2ExclusiveExecutionCondition implements ExecutionCondition { …
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184