How to get new values each test #4972
Replies: 1 comment
-
Sorry, if I'm misunderstanding but does your test look somewhat like this? fc.assert(
fc.property(
fc.emailAddress(),
customerEmail => {
// ...
database.insert({ customerEmail })
// ...
}
)
) Because the strong assumption with these tests is that no state persists across test runs. Otherwise this can badly mess with shrinking. For example, let's say the test fails (for whatever reason) when there is a customer email in the database that contains a "+". One test run inserts The test above checks "what happens if I insert a single record into the database" in a many different ways. But it sounds like what you really want to test is "what happens if I insert many records into the database". For that I would write the test like this: fc.assert(
fc.property(
fc.uniqueArray(fc.emailAddress()),
customerEmails => {
database.reset()
// ...
for (const customerEmail of customerEmails) {
database.insert({ customerEmail })
}
// ...
}
)
) Now I can also use |
Beta Was this translation helpful? Give feedback.
-
I am writing tests where data is put into a database with unique constraints. customerEmail has to be a unique value for example. Is there a way to write a test so that if I do 100 runs I won't get the same value?
Some JSONs I am generating have up to 10 unique constraints, and with a hundred test-runs I am regularly getting test failures.
Beta Was this translation helpful? Give feedback.
All reactions