gpt4 book ai didi

scala - 我如何告诉 ScalaTest 运行一个用 DoNotDiscover 注释的类?

转载 作者:行者123 更新时间:2023-12-04 12:47:49 25 4
gpt4 key购买 nike

ScalaTest 2.0不会自动运行扩展 Suite 的类但已用 DoNotDiscover 注释.但是,它“如果明确要求,它将运行带有 DoNotDiscover 注释的类,它只是不会发现它们。”

但是我如何明确要求 ScalaTest 运行这样一个 DoNotDiscover 注释类?

尽管我通过 test-only 明确指定了它们,但 ScalaTest 会忽略所有这些类。 .示例:我有这个测试套件:

@DoNotDiscover
class AnonLoginSpecRunner
extends org.scalatest.Suites(new AnonLoginSpec)
with StartServerAndChromeDriverFactory

但是当我这样做时:
[my-project] $ test-only test.e2e.specs.AnonLoginSpecRunner

ScalaTest 说:
[info] No tests to run for securesocial/test:test-only
[info] Passed: : Total 0, Failed 0, Errors 0, Passed 0, Skipped 0

我该怎么做才能让 ScalaTest 运行我的 AnonLoginSpecRunner ?

作为一种解决方法,我目前这样做:
[debiki-server] $ test:console
scala> (new test.e2e.specs.AnonLoginSpecRunner).execute()

这有效,但它有点麻烦,我想避免它。

(我使用 @DoNotDiscover 的原因是我有一个主套件,可以一劳永逸地设置 chrome 驱动程序,然后运行所有 E2E 测试规范的列表。)

最佳答案

我想出的解决方案是创建一个 shell 脚本,通过 ScalaTest 的“Runner”,通过 SBT 运行测试

如此简单 ./sbtTestFoo.sh脚本看起来像:

sbt "test:run-main org.scalatest.tools.Runner -o -s
com.foo.TestFoo"

关于scala - 我如何告诉 ScalaTest 运行一个用 DoNotDiscover 注释的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21323145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com