DEV Community

Kelly Stannard
Kelly Stannard

Posted on

1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay