Support to expose host ports via @Testcontainers for JUnit Jupiter - #4577
Closed
xhaggi wants to merge 1 commit into
Closed
Support to expose host ports via @Testcontainers for JUnit Jupiter#4577xhaggi wants to merge 1 commit into
xhaggi wants to merge 1 commit into
Conversation
Member
|
FYI #4584 provides an alternative to this that is framework agnostic, could you please have a look? |
Author
|
Could you please enlighten me how this solves the problem when using |
Member
|
Use Please share further information, why this would not solve your use case. |
Author
|
@kiview thanks, I'll give it a try and let you know if it works. |
Author
|
It works, thank you. I closed the PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, it is not possible to expose host ports when using the
@Testcontainersannotation in JUnit Jupiter due to the execution order of@BeforeAll[1] and the registration order of extensions added with@ExtendWith[2]. A method annotated with@BeforeAllwithin a test class annotated with@Testcontainersis executed after the@BeforeAllof the Testcontainers extension. If you use another extension such as WireMock in combination with@Testcontainers, the same problem occurs. The documentation [3] notes that exposing host ports should be invoked before containers are started, but after the server is started on the host.This change adds
exposeHostPortsto@Testcontainersand configures it before the containers are started.[1] https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/BeforeAll.html
[2] https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExtendWith.html
[3] https://www.testcontainers.org/features/networking/#exposing-host-ports-to-the-container