Skip to content

[Bug]: junit-jupiter brings junit 4 transitvely #6934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
snicoll opened this issue Apr 24, 2023 · 9 comments
Closed

[Bug]: junit-jupiter brings junit 4 transitvely #6934

snicoll opened this issue Apr 24, 2023 · 9 comments
Labels

Comments

@snicoll
Copy link

snicoll commented Apr 24, 2023

Module

Core

Testcontainers version

1.18.0

Using the latest Testcontainers version?

Yes

Host OS

MacOs

Host Arch

x86

Docker version

irrelevant

What happened?

Adding a dependency on org.testcontainers:junit-jupiter:jar:1.18.0 (at least with Maven) brings junit:junit:jar:4.13.2 on the test classpath.

Relevant log output

\- org.testcontainers:junit-jupiter:jar:1.18.0:test
[INFO]    \- org.testcontainers:testcontainers:jar:1.18.0:test
[INFO]       +- junit:junit:jar:4.13.2:test
[INFO]       |  \- org.hamcrest:hamcrest-core:jar:2.2:test
[INFO]       +- org.apache.commons:commons-compress:jar:1.22:test
[INFO]       +- org.rnorth.duct-tape:duct-tape:jar:1.0.8:test
[INFO]       |  \- org.jetbrains:annotations:jar:17.0.0:test
[INFO]       +- com.github.docker-java:docker-java-api:jar:3.3.0:test
[INFO]       |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.0-rc3:test
[INFO]       \- com.github.docker-java:docker-java-transport-zerodep:jar:3.3.0:test
[INFO]          +- com.github.docker-java:docker-java-transport:jar:3.3.0:test
[INFO]          \- net.java.dev.jna:jna:jar:5.12.1:test


### Additional Information

_No response_
@Jotschi
Copy link

Jotschi commented May 24, 2023

The problem is also that you can't even manually exclude it. Somehow the testcontainer jupiter API indirectly references it and custom container classes can't be compiled without junit 4 being present on the classpath. The only solution I found is
to add junit 4 back to the classpath.

@hantsy
Copy link

hantsy commented May 30, 2023

I also found this issue, it is better to upgrade Junit 5 API and support Junit 4 using Junit 5 Vintage Engine

@Illutax
Copy link

Illutax commented Jun 27, 2023

This is a duplicate of #6921 and should be closed.

cc: @rnorth @kiview @eddumelendez @bsideup

@ericdriggs
Copy link

ericdriggs commented Jan 16, 2024

Root Cause

  1. core module has an api dependency on junit 4.
  1. Generic module requires Junit 4 TestRule

Blocked on

Workaround

  • no workaround exists since junit 4 @TestRule is required on classpath

cc: @eddumelendez

@wakingrufus
Copy link
Contributor

wakingrufus commented Jul 18, 2024

the specific issue is that GenericContainer extends FailureDetectingExternalResource which implements TestRule from junit4

@ericdriggs
Copy link

ericdriggs commented Jul 19, 2024

Yes, a fix would require a complete refactor from Junit4 TestRule to Junit5 AfterEachCallback and BeforeEachCallback.
Since there's no common interface, this would be a major version breaking change with the consequence of requiring Junit5 and not supporting Junit4 for version 2.*.*

https://www.baeldung.com/junit-5-migration

@Illutax
Copy link

Illutax commented Jul 20, 2024

Junit 5 also supports Junit 4 Rules via VintageEngine. See the Junit documentation.

@ericdriggs
Copy link

ericdriggs commented Jul 22, 2024

It seems like vintage engine might provide value to testcontainers project as a transitionary point. From a client perspective it seems roughly equivalent, since the junit4 annotations are still used and you're effectively just shifting the name of the dependency artifact from junit:junit:4.* to org.junit.vintage:junit-vintage-engine:5.*. Am I missing something?

@kiview
Copy link
Member

kiview commented Jul 23, 2024

Duplicates #970.

There are a couple of stub dependencies for JUnit4 out there, that can be used as a workaround (e.g. https://github.com/xdev-software/testcontainers-junit4-mock).

@kiview kiview closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants