|
3 | 3 | import java.util.*;
|
4 | 4 | import java.util.function.*;
|
5 | 5 |
|
| 6 | +import org.assertj.core.api.*; |
6 | 7 | import org.junit.platform.engine.reporting.*;
|
7 | 8 | import org.opentest4j.*;
|
8 | 9 |
|
|
16 | 17 | import net.jqwik.testing.*;
|
17 | 18 |
|
18 | 19 | import static org.assertj.core.api.Assertions.*;
|
| 20 | +import static org.assertj.core.api.SoftAssertions.*; |
19 | 21 |
|
20 | 22 | import static net.jqwik.api.GenerationMode.*;
|
21 | 23 | import static net.jqwik.engine.TestHelper.*;
|
@@ -263,25 +265,54 @@ void usePreviouslyFailedGeneration() {
|
263 | 265 | Arbitrary<Integer> integers = Arbitraries.integers().between(1, 99);
|
264 | 266 | GenerationInfo previousGenerationInfo = new GenerationInfo("41", 13);
|
265 | 267 | // This is what's being generated from integers in the 13th attempt
|
266 |
| - List<Integer> previousSample = Arrays.asList(99, 97); |
| 268 | + List<Integer> expectedParameterValues = Arrays.asList(65, 77); |
267 | 269 |
|
268 |
| - CheckedFunction checkSample = params -> params.equals(previousSample); |
| 270 | + CheckedFunction checkSample = params -> { |
| 271 | + Assertions.assertThat(params) |
| 272 | + .describedAs("sampleProperty initial params should reuse GenerationInfo supplied in the config. " + |
| 273 | + "If you see failure here, then it looks like the random generation strategy has changed. " + |
| 274 | + "You might need to adjust expectedParameterValues = ... in usePreviouslyFailedGeneration() property test.") |
| 275 | + .isEqualTo(expectedParameterValues); |
| 276 | + return true; |
| 277 | + }; |
269 | 278 |
|
270 | 279 | CheckedProperty checkedProperty = createCheckedProperty(
|
271 | 280 | "sampleProperty", checkSample, getParametersForMethod("sampleProperty"),
|
272 | 281 | p -> Collections.singleton(integers),
|
273 | 282 | Optional.empty(),
|
274 | 283 | aConfig()
|
275 | 284 | .withPreviousFailureGeneration(previousGenerationInfo)
|
| 285 | + // Disable shrinking, so checkSample fails on the first attempt, and we can see the first failure, |
| 286 | + // and not the result of the shrinking which will be always [1, 1] |
| 287 | + .withShrinking(ShrinkingMode.OFF) |
276 | 288 | .withAfterFailure(AfterFailureMode.SAMPLE_ONLY).build(),
|
277 | 289 | lifecycleContextForMethod("sampleProperty", int.class, int.class)
|
278 | 290 | );
|
279 | 291 |
|
280 | 292 | PropertyCheckResult check = checkedProperty.check(new Reporting[0]);
|
281 |
| - assertThat(check.countTries()).isEqualTo(1); |
282 |
| - assertThat(check.seed()).isEqualTo(Optional.of("41")); |
283 |
| - assertThat(check.checkStatus()).isEqualTo(SUCCESSFUL); |
284 |
| - assertThat(check.falsifiedParameters()).isEmpty(); |
| 293 | + assertSoftly( |
| 294 | + softly -> { |
| 295 | + // Rethrow the error, so the stacktrace is meaningful, and the assert message in checkSample is printed |
| 296 | + check.throwable().ifPresent( |
| 297 | + e -> softly.assertThat(e) |
| 298 | + // softly.fail("...", e) would not print stacktrace for some reason |
| 299 | + .describedAs("checkSample property failed") |
| 300 | + .doesNotThrowAnyException() |
| 301 | + ); |
| 302 | + softly.assertThat(check.countTries()) |
| 303 | + .describedAs("check.countTries()") |
| 304 | + .isEqualTo(1); |
| 305 | + softly.assertThat(check.seed()) |
| 306 | + .describedAs("check.seed()") |
| 307 | + .contains("41"); |
| 308 | + softly.assertThat(check.checkStatus()) |
| 309 | + .describedAs("check.checkStatus()") |
| 310 | + .isEqualTo(SUCCESSFUL); |
| 311 | + softly.assertThat(check.falsifiedParameters()) |
| 312 | + .describedAs("check.falsifiedParameters()") |
| 313 | + .isEmpty(); |
| 314 | + } |
| 315 | + ); |
285 | 316 | }
|
286 | 317 |
|
287 | 318 | @SuppressWarnings("unchecked")
|
|
0 commit comments