How make tests always run in same order in Scalatest?

白昼怎懂夜的黑 提交于 2019-12-22 02:00:00

问题


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.


回答1:


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.




回答2:


See http://doc.scalatest.org/1.0/org/scalatest/SequentialNestedSuiteExecution.html

This seems to provide the specific behavior you're looking for.



来源:https://stackoverflow.com/questions/11258428/how-make-tests-always-run-in-same-order-in-scalatest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!