question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Controlling execution order of JUnit 5 extension relative to other extensions not possible

See original GitHub issue

I am trying to use this extension together with @SpringBootTest. How to ensure testcontainer starts first before executing SpringBootTest extension?

This issue is not limited to Spring, but rather an issue as soon as multiple extensions are used at the same time and a certain ordering is required.

Context

From what I see in the JUnit 5 documentation the annotation order matters. Since Java sorts annotations in bytecode alphabetically Spring will always run first unless it is possible to explicitly import @ExtendWith(TestcontainersExtension.class). Currently, this cannot be done due to TestcontainersExtension being package-private.

Possible solution

I believe making TestcontainersExtension public is all that’s needed for users to be able to explicitly define the order of multiple extensions.


Based on https://github.com/testcontainers/testcontainers-java/pull/887#issuecomment-447815105 and https://github.com/testcontainers/testcontainers-java/pull/887#issuecomment-447818414.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
aguibertcommented, Apr 14, 2019

@kiview @michael-simons I’m trying to write a new JUnit Jupiter extension that builds on top of the Testcontainers extension. The original solution proposed in this issue (make TestcontainersExtension a public class) is exactly I need, because then I can do:

@Target(TYPE)
@Retention(RUNTIME)
@ExtendWith({TestContainerExtension.class, MyExtension.class})
public @interface MyExt { }

I’m trying to follow the various issues linked in this issue to find out why the TestContainersExtension class was never made public, but didn’t find anything. Is this option still on the table?

1reaction
kiviewcommented, Dec 21, 2018

Thanks a lot for checking against #1020. Let’s try to merge it soon 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Guide to JUnit 5 Extensions - Baeldung
JUnit 5 extensions are related to a certain event in the execution of a test, referred to as an extension point. When a...
Read more >
JUnit 5 User Guide
Used to configure the test class execution order for @Nested test classes in the annotated test class. Such annotations are inherited.
Read more >
Order of multiple extensions in JUnit 5 - java - Stack Overflow
} Extensions registered declaratively via @ExtendWith will be executed in the order in which they are declared in the source code.
Read more >
Taking advantage of Junit 5 extensions - Medium
A JUnit 5 extension is connected to an occurrence of a particular event during the execution of a test. This kind of event...
Read more >
Taking advantage of Junit 5 extensions - Eric Ampire
JUnit 5 can extend the behavior of tests' classes or methods, and these extensions can be reused by many tests. A JUnit 5...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found