DEV Community

Kelly Stannard
Kelly Stannard

Posted on

Find that flaky test

A simple way to find that flaky test while you go do other things. This will run your tests over and over until it fails, at which point it will print the number of times the tests passed and open the output from the failing test run.

while rspec path/to/test_spec.rb > /tmp/last_run; do printf .; done | wc -c; less /tmp/last_run

rspec path/to/test_spec.rb > /tmp/last_run runs the tests and writes output to a tmp file.

while will loop if the test run passes and stop looping on a failure.

do printf . prints a single '.' on a test pass.

| wc -c reads the string of '.' and counts them.

less /tmp/last_run displays the last_run, which will be the failure.

Top comments (0)