|
|
|
|
|
by pytester
2580 days ago
|
|
What I found to be the major reasons for flaky tests: * Non-determinism in the code - e.g. select without an order by, random number generators, hashmaps turned into lists, etc. - Fixed by turning non-deterministic code into deterministic code, testing for properties rather than outcomes or isolating and mocking the non-deterministic code. * Lack of control over the environment - e.g. calling a third party service that goes down occasionally, use of a locally run database that gets periodically upgraded by the package manager - fixed by gradually bringing everything required to run your software under control (e.g. installing specific versions without package manager, mocking 3rd party services, intercepting syscalls that get time and replacing them with consistent values). * Race conditions - in this case the test should really repeat the same actions so that it consistently catches the flakiness. |
|
- The temperature is much hotter/colder than normal
- Someone is inadvertently holding down a button or key on the machine under test
- The wrong version of software is loaded onto the machine