我们在 ScalaTest 中使用 Spec trait 进行测试.当我们运行整个套件时,它并不总是以相同的顺序运行.谷歌中的大多数答案都建议定义一个套件并指定所有测试名称.但这需要我们每次添加新测试时都添加测试名称.
是否可以使用 DiscoverySuite 本身并定义测试执行顺序?就像按字母顺序运行测试一样.我曾考虑扩展 DiscoverySuite,但 DiscoverySuite 似乎是 scalatest 私有的.
---更多信息----
订购我的意思是,如果有测试 A、B、C.
A 类扩展规范 {..}B 类扩展规范 {..}C 类扩展 Spec {..}然后我希望测试按顺序运行(A、B、C).但现在发生的是,它每次都以不同的顺序运行.
解决方案DiscoverySuite 是 ScalaTest 私有的,是的.规范中测试的执行顺序(顺便说一下,现在称为 FunSpec)被定义为源文件中的出现顺序.要定义测试类本身的顺序,您需要定义一个nestedSuites 方法并运行该包装套件而不是使用Discovery.一旦您不再需要订单,您就可以重新使用发现.我将考虑在下一个 ScalaTest 版本中向 DiscoverySuite 添加定义的顺序.
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.
解决方案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.
更多推荐
如何使测试在 Scalatest 中始终以相同的顺序运行?
发布评论