Skip to content

Commit

Permalink
Explain lack of reproducibility for @DisabledUntil (#550 / #645)
Browse files Browse the repository at this point in the history
A test suite that only passes because a failing test is disabled
until a certain date, will fail if executed after that date. That
means the originally successful build can't be reproduced.

We're looking for a proper solution for this (see #478), but until
then, the best we can do is warn users about this in documentation
and with a report entry.

References: #478, #550
PR: 645
  • Loading branch information
Nicolai Parlog committed May 28, 2022
1 parent 5375e8e commit ef7ff7c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/disabled-until.adoc
Expand Up @@ -13,6 +13,10 @@ The only problem with this approach is remembering to activate the test again on
The `@DisabledUntil` annotation may be used to disable a test only for a certain period of time.
The test will be automatically executed again once the date supplied by the `date` parameter is reached.

WARNING: Applying `@DisabledUntil` can make the test suite non-reproducible.
If a failing test is disabled during a build that then passes, rerunning that build after the "until" date would fail.
A report entry is issued for every test that is disabled until a certain date.

== Usage

To mark a test to be temporarily disabled add the `@DisabledUntil` annotation like so:
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/junitpioneer/jupiter/DisabledUntil.java
Expand Up @@ -28,6 +28,10 @@
* <p>{@code @DisabledUntil} can be used on the method and class level. It can only be used once per method or class,
* but is inherited from higher-level containers.</p>
*
* <p><strong>WARNING:</strong> Applying {@code @DisabledUntil} can make the test suite non-reproducible. If a failing
* test is disabled during a build that then passes, rerunning that build after the "until" date would fail. A report
* entry is issued for every test that is disabled until a certain date.</p>
*
* @since 1.6.0
* @see org.junit.jupiter.api.Disabled
*/
Expand Down
Expand Up @@ -62,6 +62,10 @@ private ConditionEvaluationResult evaluateUntilDate(ExtensionContext context, Lo
boolean disabled = today.isBefore(untilDate);

if (disabled) {
String reportEntry = format(
"This test is disabled until %s. If executing it on this commit would fail, the build can't be reproduced after that date.",
untilDate.format(ISO_8601));
context.publishReportEntry("DisabledUntil", reportEntry);
String message = format("The `date` %s is after the current date %s", untilDate.format(ISO_8601),
today.format(ISO_8601));
return disabled(message);
Expand Down
Expand Up @@ -67,7 +67,7 @@ void shouldDisableTestWithUntilDateInTheFuture() {
.executeTestMethod(DisabledUntilTestCases.class, "testIsAnnotatedWithDateInTheFuture");
assertThat(results).hasNumberOfStartedTests(0);
assertThat(results).hasSingleSkippedTest();
assertThat(results).hasNoReportEntries();
assertThat(results).hasSingleReportEntry().firstValue().contains("2199-01-01", "reproduce");
}

@Test
Expand All @@ -78,7 +78,7 @@ void shouldDisableNestedTestWithUntilDateInTheFutureWhenMetaAnnotated() {
assertThat(results).hasSingleSkippedContainer(); // NestedDummyTestClass is skipped as container
assertThat(results).hasNumberOfStartedTests(0);
assertThat(results).hasNumberOfSkippedTests(0);
assertThat(results).hasNoReportEntries();
assertThat(results).hasSingleReportEntry().firstValue().contains("2199-01-01", "reproduce");
}

static class DisabledUntilTestCases {
Expand Down

0 comments on commit ef7ff7c

Please sign in to comment.