Skip to content

Commit 92f0a4f

Browse files
bmuskallabsideup
authored andcommitted
Allow @testcontainers to be inherited from superclass (#1843) (#2001)
* Updated existing test with now expected behaviour * @testcontainers is now @inherited
1 parent 43a76ab commit 92f0a4f

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

modules/junit-jupiter/src/main/java/org/testcontainers/junit/jupiter/Testcontainers.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.jupiter.api.extension.ExtendWith;
44

55
import java.lang.annotation.ElementType;
6+
import java.lang.annotation.Inherited;
67
import java.lang.annotation.Retention;
78
import java.lang.annotation.RetentionPolicy;
89
import java.lang.annotation.Target;
@@ -18,6 +19,10 @@
1819
* last test method has executed. Containers declared as instance fields will
1920
* be started and stopped for every test method.</p>
2021
*
22+
* <p>The annotation {@code @Testcontainers} can be used on a superclass in
23+
* the test hierarchy as well. All subclasses will automatically inherit
24+
* support for the extension.</p>
25+
*
2126
* <p><strong>Note:</strong> This extension has only be tested with sequential
2227
* test execution. Using it with parallel test execution is unsupported and
2328
* may have unintended side effects.</p>
@@ -52,6 +57,7 @@
5257
@Target(ElementType.TYPE)
5358
@Retention(RetentionPolicy.RUNTIME)
5459
@ExtendWith(TestcontainersExtension.class)
60+
@Inherited
5561
public @interface Testcontainers {
5662

5763
/**

modules/junit-jupiter/src/test/java/org/testcontainers/junit/jupiter/inheritance/AbstractTestBase.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import org.testcontainers.junit.jupiter.Container;
44
import org.testcontainers.junit.jupiter.Testcontainers;
55

6-
import java.util.concurrent.atomic.AtomicLong;
7-
86
@Testcontainers
97
abstract class AbstractTestBase {
108

modules/junit-jupiter/src/test/java/org/testcontainers/junit/jupiter/inheritance/InheritedTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import static org.junit.jupiter.api.Assertions.assertEquals;
88

9-
@Testcontainers
109
class InheritedTests extends AbstractTestBase {
1110

1211
@Container

0 commit comments

Comments
 (0)