Created
September 19, 2013 04:28
-
-
Save compwron/6619138 to your computer and use it in GitHub Desktop.
timed test skip for JUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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