Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • 09:41
    mpkorstanje commented #2594
  • 09:41
    mpkorstanje commented #2594
  • Apr 17 15:22

    marcphilipp on open-test-reporting

    Basic OpenTestReportGeneratingL… WIP Split package and 9 more (compare)

  • Apr 17 09:22
    marcphilipp commented #146
  • Apr 17 06:58
    t1 commented #2594
  • Apr 16 23:05
    xkrogen commented #146
  • Apr 16 18:56

    marcphilipp on main

    Remove suite projects from JaCo… (compare)

  • Apr 16 18:51

    junit-buildmaster on gh-pages

    Generated by gradle-git-publish. (compare)

  • Apr 16 18:49

    marcphilipp on main

    Fix circular dependency in Ecli… (compare)

  • Apr 16 18:34

    marcphilipp on main

    Disable inferring module path t… (compare)

  • Apr 16 16:37

    junit-buildmaster on gh-pages

    Generated by gradle-git-publish. (compare)

  • Apr 16 16:30

    sbrannen on main

    Include 5.8 M2 in the generated… (compare)

  • Apr 16 16:22
    sbrannen commented #2591
  • Apr 16 16:21
    sbrannen edited #2591
  • Apr 16 16:21
    sbrannen closed #2591
  • Apr 16 16:21

    sbrannen on main

    Introduce Named.named() as an a… Polish Named Javadoc and add pr… (compare)

  • Apr 16 15:46
    xkrogen commented #146
  • Apr 16 14:42
    mklueh commented #1967
  • Apr 16 14:28
    codecov[bot] commented #2598
  • Apr 16 14:27

    marcphilipp on main

    Tabs or spaces, not both (compare)

Hi Guys, is it possible to build a fat jar, which contains JUNIT5 and co, including the console launcher, and run from command line without a local copy of the console launcher?
1 reply
Daniel Svensson
Is there any known issues with @TempDir as a static member of an abstract base-class for tests marked as @TestInstance(TestInstance.Lifecycle.PER_CLASS) together with concurrently running classes inheriting that base class? A lot of the classes (but not all) seem to get the same tempdir, and it also seems like the directory is deleted by other classes causing running all tests at the same time to fail some of the tests. I'm using Kotlin and I have @TempDir as a companion object member marked as @JvmStatic, on JUnit 5.7. Concurrency configured via: junit.jupiter.execution.parallel.enabled=true, junit.jupiter.execution.parallel.mode.default=same_thread, junit.jupiter.execution.parallel.mode.classes.default=classes.
Daniel Svensson
The problem seems to go away if I move the @TempDir from a static member of the abstract class, to a @BeforeAll method parameter, setting the local member from there instead. I guess the static isn't reinitialized per lifecycle.

Hiya - new here, so please be kind... (or not).

Naturally, I'm here with a problem: Not only can I not control the order in which test classes are executed (NOT "method order"), but the order isn't even "sensible" (to me). Please don't tell me that "[we] shouldn't write tests that care about order."

I can explain more richly why I need such, but here's what I would like to have: test classes in the plan to be run in "package partial-order." Thus, once test classes from a certain package begin, then all tests under that package are completed before moving on outside that package. (I think this amounts to a partial ordering. From a package-tree walking perspective, it would be depth first, but not necessarily ordered for sub-packages of the same parent package.)

11 replies
Daniel Svensson
How do I get gradle/junit to parallellize tests to match the CPU cores when having a multi-project setup? Feels like each subproject fires up as many threads as I have cores?
1 reply
Daniel Svensson
To avoid overbooking of the CPU
M.P. Korstanje

Evening, it's been a while since I last checked out JUnit 5. Right now when I open the project in IDEA 2020.3 it looks all sorts of messed up and won't build at all.

I'm guessing IDEA and Gradle aren't quite in line here but I'm an expert in neither so I'm wondering if this is just me or if it's a structural problem.

I've already tried closing the project and running git clean -dfx to get rid of any junk.

M.P. Korstanje
Specifically the problem seems to be that all src/main folders in a module are imported by IDEA as a new module rather then as a source folder.
Right found it.
  1. Exit IDEA.
  2. git clean -dfx
  3. /graldlew idea
  4. Open the generated junit5.ipr file (not the root folder) in IDEA.
Michael McKay
I'm using junit5 with Ant and found that parameterized tests that use the @DisplayName annotation are not handled well by the legacy-xml report writer. Instead of the parameters used in the test description, there is a repeated entry of the test method name. Does anyone know of a XML report writer that would better handle the @DisplayName annotation while still generating the junit xml report format?
Mark Raynsford
hello! i'm migrating a project from junit 4 to junit 5, and it's using a custom @PercentagePassing rule. the rule is applied to tests that are sensitive to floating point imprecision, and essentially runs each test a thousand times and then checks that ≥ 98% of the runs didn't result in an exception: https://github.com/io7m/jregions/tree/develop/com.io7m.jregions.tests/src/test/java/com/io7m/jregions/tests/rules
i can move these tests to using @RepeatedTest(1000), but i clearly need to write an extension that counts the number of successes and failures for a given test, and i'm unable to work out from the documentation which parts of the extension API i need
could someone point me in the right direction?
Mark Raynsford
looks like someone already put together something similar here: https://stackoverflow.com/questions/46181026/junit5-how-to-repeat-failed-test
Mark Raynsford
seems invalid, frankly. it declares an extension without a public no-arg constructor, and uses it in contexts that will cause junit to try to call that nonexistent constructor
Mark Raynsford
i'm returning a stream of context values from TestTemplateInvocationContextProvider.provideTestTemplateInvocationContexts(). is there a way to access those context values from TestExecutionExceptionHandler.handleTestExecutionException()? i can see the context value in the test descriptor inside the ExecutionContext passed to the method, but it doesn't seem like there are any public methods that will allow me to access it
Mark Raynsford
place them in a Store
Michael McKay
@io7m Hi Mark, have a look at the TestExecutionListener and the classes that implement it. It provides a way to hook into the test execution process and could perform the count you require. I use it to provide custom console outputs during test execution. I'm unsure if it can affect the results of a test but it may provide clues as to how to go about it.
Mark Raynsford
@mckayERP thanks! unfortunately, i've already looked there and it doesn't seem like you can affect the results of a test. the basic problem i'm wrestling with is that i want to be able to prevent exceptions raised by individual invocations in a @TestTemplate from failing the test as a whole, and then i want to be notified when all invocations have occurred so that i can decide whether or not the test has failed as a whole
it seems like this is just outright not possible with any of the APIs, and that seems bizarre to me
i can, for example, ignore all exceptions thrown by template methods, logging them instead to my own context value. the problem with this is that then the IDE will show those test invocations as having succeeded, when they clearly didn't
i might have to live with that
Mark Raynsford
it seems i can throw TestAbortedException in order to "ignore" individual template invocations. that seems a little abusive, but it does at least get the IDE to show something other than success for the tests
Mark Raynsford
is there any particular API that extensions should use for logging? my extension code currently just grabs an SLF4J logger
i notice there's something that looks very much like SLF4J embedded into the org.junit.platform.commons.logging package
the API is marked as INTERNAL, however, and the package only seems to be exported to some specific modules
Mark Raynsford
https://github.com/io7m/percentpass/ if anyone's interested
Adrian Woodhead
@io7m we have a very similar requirement - we are working on mutation testing from JUnit where we take the original test method and then produce a number of mutated variants of this - if a mutation fails that's actually a good thing. So what we want to do is: 1. run the original un-mutated test -> if this fails mark test as failed and stop; otherwise carry on with 2. run the mutations; 3. once all mutants are finished -> gather their results to produce a report but mark the overall test as success (i.e. don't pass on their failures). We also couldn't find a way to intercept and modify the test result. We'll take a look at what you did but it sounds like some kind of feature in JUnit to do this would be more broadly useful. We were able to do this in JUnit4.
3 replies
Deepak Bhimaraju
Given the following Junit5 test class, how do I run upperCaseTest and lowerCaseTest in parallel while the parameterized runs within each test method run in sequence. In other words, "A", "B" and "C" should run in sequence, "x", "y", "z" should run in sequence but "A" and "x" should be able to run in parallel.
class ParallelParameterizedTest {

    @ValueSource(strings = {"A", "B", "C"})
    void upperCaseTest(String s) {
        assertEquals(s.toUpperCase(), s);

    @ValueSource(strings = {"x", "y", "z"})
    void lowerCaseTest(String s) {
        assertEquals(s.toLowerCase(), s);
3 replies
Hi, i hope you can help me.
I am currently switching to use the module path (jigsaw) instead.
Now everything is running fine with maven surefire/failsafe but i get exceotions running it with the eclipse junit launcher. are there any general recommendations for that.
Deepak Bhimaraju
Hi again, could someone reply to my comment on the thread above? Link to my comment: https://gitter.im/junit-team/junit5?at=60084ab8410c2214400fc7ae Thanks!
Soheil Pourbafrani

Hi everybody,
In my test case, I have the test methods in multiple packages and classes, and it works such that an init Method should be executed once (once for all packages, not each) before test executions, and then we can execute the test methods against that.

The problem is I couldn't find a way to specify a method to be executed once before all test classes, however inside each class using the @BeforeClass tag I can specify the init method with works only for testing the class methods, not all classes.

I'm runnings tests using maven does the surefire plugin support any utility that can be used for my case?
Any help would be appreciated


Georgios Andrianakis

Hey folks,

I don't see a way for a test extension to know to the configured tags when it runs.
Is there something I haven't seen or something that makes sense to add an issue for enhancement?


Daniyar Yeralin

Hi guys, is there any reason why this snippet fails?

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

import java.sql.Connection;
import java.sql.DriverManager;
import org.mockito.Mock;
import org.mockito.MockedStatic;

Connection mockConnection = mock(Connection.class);
try(MockedStatic<DriverManager> mockedDriverManager = mockStatic(DriverManager.class)) {
    mockedDriverManager.when(() -> DriverManager.getConnection(any(), any(), any())).thenReturn(mockConnection);

If I execute this snippet, it throws:

when() requires an argument which has to be 'a method call on a mock'.

Although according to all tutorials I followed, it is supposed to work :(

6 replies
Timur Mirzoev

Hi people, I've encountered a problem when running multiple parallel tests that actively use Future.getAsync().get()

Basically its very similar to this issue junit-team/junit5#1675 where additional tests are run over the desired parallelism count, but a bit worse: if parallelism is large enough, and test amount is large enough, ForkJoinPool starts creating threads over the maxPoolSize limit, and tests start failing with RejectedExecutionException.

So, while looking for the solution, I've found how to tune ForkJoinPool used by Junit in a way that prevents raising RejectedExecutionException. Now, the problem is, that to customize FJP instantiation, I have to override ForkJoinPoolHierarchicalTestExecutorService and subsequently, provide an custom JupiterEngine to use that ForkJoinPoolHierarchicalTestExecutorService.

I'd like to know, if it is possible to override FJP creation more easily or if someone's already stumbled upon this and found a simpler solution to this excessive threading problem.

6 replies
Ilamparithi Natarajan

I tried running multiple @ WebMvcTest s in concurrent mode with
junit.jupiter.execution.parallel.enabled = true junit.jupiter.execution.parallel.mode.default = concurrent
in junit-platform.properties

sometimes test fail because mock did not behave in the way it was supposed to (either mockbean was null or the mocked method returned null. anyone faced this issue?

Matthias Ngeo
When implementing a TestInstanceFactory, how do I create a test instance that has a constructor with parameters to be resolved by other extensions? I looked through the documentation but could not find any relevant information on it. It is even possible?
Thilo-Alexander Ginkel
Hi there! I am trying to use a @ParameterizedTest with a @MethodSource to write a test that is testing different implementations of an interface. Unfortunately, I need a @TempDir to construct the instances under test. Is there a way to combine @MethodSource and TempDir? Thanks!
1 reply
Hi there, I am trying to understand if JUnit (not just JUnit 5 but all versions) are the most popular java testing framework. I am pretty sure it is anecdotally but is there any data to prove this? Any links to stats? Thank you :)
3 replies
Mykola Bova
Hi Team! A question about integration tests. Is in required to have Test test postfix to run tests from maven? What is the best way to handle IT tests - test is not running from mvn test unless if it is not postfixed by Test Or this is maven problem?
Mykola Bova
Ok Here is an answer
Hi everyone, does anyone know if it is possible in Junit 5 to learn what number retry is being run, or run some extra logic only on test runs that are a retry? For example, I'm using Failsafe with Junit 5. Failsafe has a configuration option "<rerunFailingTestsCount>", and while their documentation says it only works with Junit 4, it has been working just fine for me in Junit5. For my integration tests, I'd like to set up a screen and screen recorder/take a video recording, and enable more verbose logging output, but ONLY on the final try of a set of retries; I don't want to have the screen and screen recorder running for 100 tests if I only have 1 that fails all of it's retries. In the past, using Junit 4, I had overridden Evaluate and Statement in order to simply loop for X times (X being my configurable number for how many times I want a given test to be able to retry before failing the test suite) if evaluate failed (thus implementing my own rigged-up retry rule). And then if currentRetry == X, start up the screen/recorder/verbose logging/test-step tracker, etc for this particular run of this specific test. It worked very well, and I'm wondering how to accomplish something similar in Junit 5. Is there an analogue to the Statement and Evaluate system from Junit 4 inside Junit 5? Is my desired outcome something that is possible already through an annotation or extension/interface that I've simply missed in my googling? Any direction is appreciated, and let me know if this is unclear or in the wrong place. Thanks in advance!
1 reply
Rachit Sharma

Pardon this novice, using JUnit5 Jupiter to test multithreaded kafka consumers. Used KakfaConsumer poll() method inside a forever while loop (while (true) ) as need to poll the records regularly.

Code to be tested:

public void pollRecordsFromKafkaMsk(Cipher cipher) {

    AtomicInteger i = new AtomicInteger();

    ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);

    for (Topic topic : kafkaTopicProperties.getTopics()) {
        Runnable runnable = () -> {

            Thread.currentThread().setName("Consumer-" + i.getAndIncrement());
            KafkaConsumer<String, String> consumer = createConsumerAndSubscribe(topic.getTopicName());

            log.info("consumer created:: {} on thread:: {}", consumer, Thread.currentThread().getName());

            while (true) {
                pollAndProcessRecords(topic, consumer, cipher);

Challenge I am facing, when my build pipeline runs the test method, it runs forever.

Using , Java8, Spring Kafka and Junit5 Jupiter.

trying to use timeout but not seeing any good.

@Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
public void pollRecordsFromKafkaMskTest() {

Any expert advice will be highly appreciated.

6 replies
I keep running into the issue where I am unable to import JUnit 5 from hovering over a a text and I checked the plugins to make sure I have JUnit, how can I resolve this issue?
Alan Zimmer

Is it possible to parameterize a test class?

I'm looking to enable a scenario where a test class has a set of values which should be tested against, while having parameterized test methods contained within it.

Christian Stein
Sounds like what is described here: junit-team/junit5#871 and junit-team/junit5#878 and in various linked friends.
Thus, the short answer is: no. Not possible at the moment.