如何使测试在 Scalatest 中始终以相同的顺序运行?

编程入门 行业动态 更新时间:2024-10-19 07:27:12
本文介绍了如何使测试在 Scalatest 中始终以相同的顺序运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们在 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 中始终以相同的顺序运行?

本文发布于:2023-11-25 15:24:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630286.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   测试   Scalatest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!