Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How make tests always run in same order in Scalatest?

We use Spec trait for our tests in ScalaTest. when we run the entire suite, it does not always run in the same order. Most answers in google suggest defining a Suite and specifying all the test names. But this requires us to add the test name every time we add a new test.

Is it possible to use the DiscoverySuite itself and define the test execution order? Like run the tests in alphabetical order. I looked at extending the DiscoverySuite but DiscoverySuite seems to be private to scalatest.

---More info----

By ordering i mean, If there are tests A, B, C.

class A extends Spec  {..}
class B extends Spec  {..}
class C extends Spec  {..}

Then i want the tests to run in order (A, B, C). But what happens now is, it run in a different order everytime.

like image 585
Udayakumar Rayala Avatar asked Jun 29 '12 08:06

Udayakumar Rayala


1 Answers

DiscoverySuite is private to ScalaTest, yes. The execution order of tests in a Spec (now called FunSpec, by the way) is defined to be the order of appearance in the source file. To define the order of the test classes themselves, you will need to define a nestedSuites method and run that wrapper Suite instead of using Discovery. You can go back to using discovery once you no longer need an order. I'll look at adding a defined order to DiscoverySuite in the next ScalaTest release.

like image 62
Bill Venners Avatar answered Oct 02 '22 16:10

Bill Venners