Skip to content

Instantly share code, notes, and snippets.

@compwron
Created September 19, 2013 04:28
Show Gist options
  • Save compwron/6619138 to your computer and use it in GitHub Desktop.
Save compwron/6619138 to your computer and use it in GitHub Desktop.
timed test skip for JUnit
import org.joda.time.DateTime;
import org.junit.Test;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
public class TimedIgnoreTest {
@Test
public void shouldRunBecauseAssumptionHasTimedOut() {
runOnDateBecause("2012-01-01", "todays date is past 2012");
fail("See message from runOnDateBecause");
}
@Test
public void shouldNotRunBefore2020BecauseAssumptionHasNotTimedOut() {
runOnDateBecause("2020-01-01", "today's date is past 2020-01-01");
fail("See message from runOnDateBecause");
}
private void runOnDateBecause(String date, String reasonToStartRunning) {
if (new DateTime().isAfter(new DateTime(date))) { // May have to replace this with non-Joda date parsing in older codebases
// Logger.log("Running test because " + reasonToStartRunning);
System.out.println("Running test because " + reasonToStartRunning);
} else {
assumeTrue(false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment