|
| 1 | +package com.carrotsearch.randomizedtesting.jupiter; |
| 2 | + |
| 3 | +import static com.carrotsearch.randomizedtesting.jupiter.infra.TestInfra.*; |
| 4 | +import static org.junit.platform.testkit.engine.EventConditions.*; |
| 5 | + |
| 6 | +import com.carrotsearch.randomizedtesting.jupiter.infra.IgnoreInStandaloneRuns; |
| 7 | +import org.assertj.core.api.Assertions; |
| 8 | +import org.junit.jupiter.api.Nested; |
| 9 | +import org.junit.jupiter.api.RepeatedTest; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | + |
| 12 | +/** Ensure there is a way to quickly "fix" the seed for the given method or class. */ |
| 13 | +public class F004_SeedFixing { |
| 14 | + @Nested |
| 15 | + class TestSeedAnnotation { |
| 16 | + @Test |
| 17 | + public void testSeedFixing() { |
| 18 | + collectExecutionResults( |
| 19 | + testKitBuilder(T1.class) |
| 20 | + .configurationParameter( |
| 21 | + RandomizedContextSupplier.SysProps.TESTS_SEED.propertyKey, "dead:beef:cafe")) |
| 22 | + .results() |
| 23 | + .allEvents() |
| 24 | + .assertThatEvents() |
| 25 | + .doNotHave(event(finishedWithFailure())); |
| 26 | + } |
| 27 | + |
| 28 | + @Randomized |
| 29 | + static class T1 extends IgnoreInStandaloneRuns { |
| 30 | + @Test |
| 31 | + @FixSeed("babe") |
| 32 | + void simpleTest(RandomizedContext ctx) { |
| 33 | + Assertions.assertThat(ctx.getSeedChain().toString()).isEqualTo("[DEAD:BEEF:BABE]"); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testClassSeedFixing() { |
| 39 | + collectExecutionResults( |
| 40 | + testKitBuilder(T2.class) |
| 41 | + .configurationParameter( |
| 42 | + RandomizedContextSupplier.SysProps.TESTS_SEED.propertyKey, "dead")) |
| 43 | + .results() |
| 44 | + .allEvents() |
| 45 | + .assertThatEvents() |
| 46 | + .doNotHave(event(finishedWithFailure())); |
| 47 | + } |
| 48 | + |
| 49 | + @Randomized |
| 50 | + @FixSeed("babe") |
| 51 | + static class T2 extends IgnoreInStandaloneRuns { |
| 52 | + @Test |
| 53 | + void ta(RandomizedContext ctx) { |
| 54 | + Assertions.assertThat(ctx.getSeedChain().toString()).startsWith("[DEAD:BABE:"); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + void tb(RandomizedContext ctx) { |
| 59 | + Assertions.assertThat(ctx.getSeedChain().toString()).startsWith("[DEAD:BABE:"); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + @Randomized |
| 64 | + @FixSeed("babe:caca") |
| 65 | + static class T3 extends IgnoreInStandaloneRuns { |
| 66 | + @Test |
| 67 | + void ta(RandomizedContext ctx) { |
| 68 | + Assertions.assertThat(ctx.getSeedChain().toString()).startsWith("[DEAD:BABE:CACA]"); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + void tb(RandomizedContext ctx) { |
| 73 | + Assertions.assertThat(ctx.getSeedChain().toString()).startsWith("[DEAD:BABE:CACA]"); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void testRepeatedTests() { |
| 79 | + collectExecutionResults( |
| 80 | + testKitBuilder(T4.class) |
| 81 | + .configurationParameter( |
| 82 | + RandomizedContextSupplier.SysProps.TESTS_SEED.propertyKey, "dead")) |
| 83 | + .results() |
| 84 | + .allEvents() |
| 85 | + .assertThatEvents() |
| 86 | + .doNotHave(event(finishedWithFailure())); |
| 87 | + } |
| 88 | + |
| 89 | + @Randomized |
| 90 | + static class T4 extends IgnoreInStandaloneRuns { |
| 91 | + @RepeatedTest(5) |
| 92 | + @FixSeed("babe") |
| 93 | + void simpleTest(RandomizedContext ctx) { |
| 94 | + Assertions.assertThat(ctx.getSeedChain().toString()).endsWith(":BABE]"); |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments