Does this package is useful for unit testing? #1030
-
In my company, the devs like to use this package for unit test inputs but, although already knew this package I do not use it for unit tests because in my vision this can cause random failures that will not happen again when a re-run the test, creating inconsistent tests and this sounds bad I'm missing something and this is a safe use for faker? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Absolutely, I use it myself for unit tests and integration tests. |
Beta Was this translation helpful? Give feedback.
-
Just to be clear for strict unit testing this is probably not a good idea since you want consistent, deterministic test runs that are replicable. You could achieve that by always using the same seed for faker during your test runs. However, I understand that this may not align with your original intention. Nonetheless, there is a concept fuzz testing (fuzzing) which falls within the realm of higher-level unit tests. These tests are designed to catch bugs on edge cases in your software. In this context, Faker would be a perfect tool for fuzz testing - a tool that generates input data for your tests. Overall, I would agree with @Shinigami92. Personally, I use Faker for my personal and professional unit tests, and never had any significant problems. |
Beta Was this translation helpful? Give feedback.
Absolutely, I use it myself for unit tests and integration tests.
Make sure to log out the
seed
somewhere so if there is a failing test you can reproduce the failing test case!