Replies: 3 comments 1 reply
-
In case it helps someone else, I ended up passing custom seed value using a @Seed annotation on a test method. This was implemented using @Seed(123)
@Test
void verifyPerson() {
Person person = Instancio.of(Person.class).create();
// ... |
Beta Was this translation helpful? Give feedback.
-
Instead of using a static method on The instance could the be pre-seeded. |
Beta Was this translation helpful? Give feedback.
-
Why don't you inject your factory created Person instance into the test method as an argument? Similar to what the ParameterizedTest variants do. That way the code of the test methods would remain unchanged for re-running with a fixed seed, since the injection can provide the non-random value the second time. I would probably use a -Dfoo.bar.seed=123 system property to set a wanted seed at wherever the test runtime is launched. That way a single argument for the seed can be used with 1 or 1000 tests, while your suggestion above doesn't really scale. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I'm working on a library that populates objects with random data via reflection: https://github.com/instancio/instancio
I would like to integrate the library with JUnit 5 so that if a test fails, I can display the
seed
value that was used by the random number generator in the failure message. This would allow the user to reproduce the failed test by supplying the seed value back to the library and re-running the test.Example:
I would like to report the following message:
Second test run:
I was thinking of creating an extension and putting the value into the
ExtensionContext.store
,but I couldn't figure out how to pass the data from the library into the store.
Would this be possible to achieve?
Beta Was this translation helpful? Give feedback.
All reactions