Skip to content
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

Support TestLifecycleAware-ness of containers started by the JUnit Jupiter integration #1326

Merged
merged 41 commits into from Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
63764ca
Update BrowserWebDriverContainer to honor existing no_proxy setting
roamingthings Oct 21, 2018
3281ac5
Update test to only start one container per test
roamingthings Oct 22, 2018
631b9b3
Use constant for no_proxy key
roamingthings Oct 22, 2018
6c8f08c
Cleanup test implementation (#929)
roamingthings Feb 2, 2019
3143068
Merge branch 'master' into master
roamingthings Mar 7, 2019
4a1ffe0
Merge branch 'master' into master
roamingthings Mar 12, 2019
8c07732
Merge branch 'master' into master
rnorth Mar 17, 2019
a7ccf50
Merge branch 'master' into master
kiview Mar 19, 2019
7a9f69a
Merge remote-tracking branch 'remotes/upstream/master'
roamingthings Mar 19, 2019
c91d344
Add signalling of TestLifecycleAware containers.
roamingthings Feb 6, 2019
a6998eb
#1326 Add early draft to test signalling of TestLifecycleAware contai…
roamingthings Mar 19, 2019
e5a158d
Add test for post condition when signalling lifecycleaware containers
roamingthings Mar 27, 2019
a7fd8fd
Merge remote-tracking branch 'upstream/master'
roamingthings Jul 7, 2019
c374056
Merge branch 'master' into juni5_lifecycleaware
roamingthings Jul 7, 2019
a58a986
Merge remote 'upstream/master' into juni5_lifecycleaware
roamingthings Jul 21, 2019
ee1dae7
Update test for lifecycle aware containers to cover shared case (#1326)
roamingthings Jul 23, 2019
deabf8a
Merge remote-tracking branch 'upstream/master' into juni5_lifecycleaware
roamingthings Jul 23, 2019
63c723d
Update test for lifecycle aware containers to cover shared case (#1326)
roamingthings Jul 23, 2019
20eea51
Merge branch 'master' into juni5_lifecycleaware
roamingthings Sep 15, 2019
7971b3a
Merge branch 'master' into juni5_lifecycleaware
roamingthings Oct 18, 2019
61ac0c3
Merge branch 'master' into juni5_lifecycleaware
roamingthings Nov 1, 2019
93fb685
Fix formatting (#1326)
roamingthings Nov 1, 2019
13b526e
Use lighter container for testing (#1326)
roamingthings Nov 1, 2019
eb67ee2
Separate store and collect of shared lifecycle-aware-containers (#1326)
roamingthings Nov 1, 2019
37014cc
Add tests for ordering and capturing test exceptions (#1326)
roamingthings Nov 1, 2019
33b1e7b
Merge branch 'master' into juni5_lifecycleaware
roamingthings Dec 23, 2019
6013273
Make lifecycle tests independent of timing (#1326)
roamingthings Dec 23, 2019
5de31c8
Make mock now implements Startable (#1326)
roamingthings Dec 23, 2019
cef26a3
Merge branch 'master' into juni5_lifecycleaware
rnorth Jan 18, 2020
9abd4e6
Add AssertJ dependency (#1326)
roamingthings Jan 19, 2020
43ec440
Migrate assertions of TestLifecycleAwareMethodTest to AssertJ (#1326)
roamingthings Jan 19, 2020
856da3f
Update generation of filesystem friendly description (#1326)
roamingthings Jan 19, 2020
8689dda
Merge remote-tracking branch 'origin/juni5_lifecycleaware' into juni5…
roamingthings Jan 19, 2020
c93cebd
Separated tests for filesystem friendly filename (#1326)
roamingthings Jan 23, 2020
605d46a
Merge branch 'master' into juni5_lifecycleaware
roamingthings Feb 25, 2020
d25dc8c
Merge branch 'master' into juni5_lifecycleaware
roamingthings Feb 29, 2020
2fbdf85
Use lombok to improve readability (#1326)
roamingthings Feb 29, 2020
6f4f83a
Generate filesystem friendly name from display name (#1326)
roamingthings Feb 29, 2020
8297f42
Merge branch 'master' into juni5_lifecycleaware
roamingthings Apr 4, 2020
261e470
Generate filesystem friendly name from URLEncoded unique id (#1326)
roamingthings Apr 4, 2020
9690e50
Merge branch 'master' into juni5_lifecycleaware
roamingthings Apr 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,6 +16,7 @@
import org.testcontainers.lifecycle.TestLifecycleAware;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -99,17 +100,16 @@ private void signalAfterTestToContainersFor(String storeKey, ExtensionContext co
}

private TestDescription testDescriptionFrom(ExtensionContext context) {
return new TestDescription() {
@Override
public String getTestId() {
return context.getUniqueId();
}
return new TestcontainersTestDescription(
context.getUniqueId(),
filesystemFriendlyNameOf(context)
);
}

@Override
public String getFilesystemFriendlyName() {
return context.getDisplayName();
}
};
private String filesystemFriendlyNameOf(ExtensionContext context) {
return context.getRequiredTestClass().getName()
+ "-"
+ context.getTestMethod().map(Method::getName).orElse("static");
bsideup marked this conversation as resolved.
Show resolved Hide resolved
}

private boolean isTestLifecycleAware(StoreAdapter adapter) {
Expand Down
@@ -0,0 +1,20 @@
package org.testcontainers.junit.jupiter;

import lombok.RequiredArgsConstructor;
import org.testcontainers.lifecycle.TestDescription;

@RequiredArgsConstructor
roamingthings marked this conversation as resolved.
Show resolved Hide resolved
public class TestcontainersTestDescription implements TestDescription {
roamingthings marked this conversation as resolved.
Show resolved Hide resolved
private final String testId;
private final String filesystemFriendlyName;

@Override
public String getTestId() {
return testId;
}

@Override
public String getFilesystemFriendlyName() {
return filesystemFriendlyName;
}
}
Expand Up @@ -14,12 +14,14 @@ public class TestLifecycleAwareContainerMock implements Startable, TestLifecycle
static final String AFTER_TEST = "afterTest";

private final List<String> lifecycleMethodCalls = new ArrayList<>();
private final List<String> lifecycleFilesystemFriendlyNames = new ArrayList<>();

private Throwable capturedThrowable;

@Override
public void beforeTest(TestDescription description) {
lifecycleMethodCalls.add(BEFORE_TEST);
lifecycleFilesystemFriendlyNames.add(description.getFilesystemFriendlyName());
}

@Override
Expand All @@ -36,6 +38,10 @@ Throwable getCapturedThrowable() {
return capturedThrowable;
}

public List<String> getLifecycleFilesystemFriendlyNames() {
return lifecycleFilesystemFriendlyNames;
}

@Override
public void start() {

Expand Down
Expand Up @@ -41,15 +41,27 @@ void should_prepare_before_and_after_test() {

@Test
@Order(2)
void should_call_beforeTest_first_afterTest_later() {
assertThat(startedTestContainer.getLifecycleMethodCalls()).containsExactly(BEFORE_TEST, AFTER_TEST);
void should_call_beforeTest_first_afterTest_later_with_filesystem_friendly_name() {
assertThat(startedTestContainer.getLifecycleMethodCalls())
.containsExactly(BEFORE_TEST, AFTER_TEST);
// Usually this would be a separate test, but due to the complex setup this is done here as well
assertThat(startedTestContainer.getLifecycleFilesystemFriendlyNames())
.containsExactly(
"org.testcontainers.junit.jupiter.TestLifecycleAwareMethodTest-should_prepare_before_and_after_test"
);
}

static class SharedContainerAfterAllTestExtension implements AfterAllCallback {
// Unfortunately it's not possible to write a @Test that is run after all tests
@Override
public void afterAll(ExtensionContext context) {
assertThat(SHARED_CONTAINER.getLifecycleMethodCalls()).containsExactly(BEFORE_TEST, AFTER_TEST);
assertThat(SHARED_CONTAINER.getLifecycleMethodCalls())
.containsExactly(BEFORE_TEST, AFTER_TEST);
// Usually this would be a separate test, but due to the complex setup this is done here as well
assertThat(SHARED_CONTAINER.getLifecycleFilesystemFriendlyNames())
.containsExactly(
"org.testcontainers.junit.jupiter.TestLifecycleAwareMethodTest-static"
);
}
}
}