Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sbt test continually until a flakey test fails?

Tags:

scala

sbt

If there is a test that fails only sometimes, can I ask sbt to run tests continually until failure?

Otherwise, I'm stuck hitting up-arrow while watching Arrow. (pun unintended but leavening)

https://stackoverflow.com/q/22366719/1296806

like image 244
som-snytt Avatar asked Mar 13 '14 08:03

som-snytt


People also ask

What is the difference between flaky and failing tests?

A failing test is a test that fails consistently across multiple reruns A flaky test is a test that eventually passes across reruns if the test reruns multiple times We wanted to create a system that would detect flaky tests and calculate flakiness percentage based on the test history.

How long does it take to follow a flaky test?

Flaky tests are statistical by nature, so you’ll need to follow a test over a few days to understand its behavior. The more it runs, the more likely a pattern will emerge.

How do you pass a flaky test?

Leave the flaky tests branch alive and building until no repeating flaky test appears for a longer period of time. A popular solution that hides flaky test failures is to re-run the failed tests a few times until they pass. If a test passes at least once, it is declared as passed.

What are the maintenances of flaky tests?

These flaky tests have to be maintained regularly for every test done or have feedback loops so that every steps or change of the tests are done correctly. These maintenances or feedback loops usually end up slowing down the process of development drastically.


2 Answers

Old question, but having just had the same need myself, here is a solution: sbt will return non-zero exit code if you run it one off with the tests, so, one way to loop until it fails is to just look at the exit code in the shell:

while [ $? -eq 0 ]; do sbt test; done
like image 88
johanandren Avatar answered Oct 20 '22 09:10

johanandren


I had the same problem, and I've ended up implementing this as a command.

lazy val root = Project("test", file(".")).
  settings(commands += Command.command("testUntilFailed") { state =>
    "test" :: "testUntilFailed" :: state
  })

The advantage is that it will skip the SBT loading. You can also add extra parameter or run testOnly to test a single test.

like image 26
lpiepiora Avatar answered Oct 20 '22 10:10

lpiepiora