gpt4 book ai didi

scala - 如何跳过 FlatSpec 中的测试?

转载 作者:行者123 更新时间:2023-12-01 08:22:45 25 4
gpt4 key购买 nike

我知道单元测试已损坏:

it should "be true" in {
assert(false)
}

但是我现在不想修复它,而是将其标记为已跳过。在测试运行的输出中应该有一个高度可见且非常简洁的警告,这就是为什么注释代码是不够的。

我找到了 cancel命令:
it should "be true" in {
cancel("skipped")
assert(false)
}

虽然这在控制台中通过 sbt test 看起来不错:
[info] - should be true !!! CANCELED !!!

它使用巨大的堆栈跟踪向 IntelliJ 中的控制台发送垃圾邮件:
Test Canceled: skipped


org.scalatest.exceptions.TestCanceledException: skipped
at org.scalatest.Assertions.newTestCanceledException(Assertions.scala:531)
at org.scalatest.Assertions.newTestCanceledException$(Assertions.scala:530)
at org.scalatest.FlatSpec.newTestCanceledException(FlatSpec.scala:1685)
at org.scalatest.Assertions.cancel(Assertions.scala:1141)
at org.scalatest.Assertions.cancel$(Assertions.scala:1137)
at org.scalatest.FlatSpec.cancel(FlatSpec.scala:1685)
at com.dreamlines.metronome.entities.MarshallingTest.$anonfun$new$3(MarshallingTest.scala:108)
at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1682)
at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
at org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1685)
at org.scalatest.FlatSpecLike.invokeWithFixture$1(FlatSpecLike.scala:1680)
at org.scalatest.FlatSpecLike.$anonfun$runTest$1(FlatSpecLike.scala:1692)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.FlatSpecLike.runTest(FlatSpecLike.scala:1692)
at org.scalatest.FlatSpecLike.runTest$(FlatSpecLike.scala:1674)
at org.scalatest.FlatSpec.runTest(FlatSpec.scala:1685)
at org.scalatest.FlatSpecLike.$anonfun$runTests$1(FlatSpecLike.scala:1750)
at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:396)
at scala.collection.immutable.List.foreach(List.scala:389)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:379)
at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:461)
at org.scalatest.FlatSpecLike.runTests(FlatSpecLike.scala:1750)
at org.scalatest.FlatSpecLike.runTests$(FlatSpecLike.scala:1749)
at org.scalatest.FlatSpec.runTests(FlatSpec.scala:1685)
at org.scalatest.Suite.run(Suite.scala:1147)
at org.scalatest.Suite.run$(Suite.scala:1129)
at org.scalatest.FlatSpec.org$scalatest$FlatSpecLike$$super$run(FlatSpec.scala:1685)
at org.scalatest.FlatSpecLike.$anonfun$run$1(FlatSpecLike.scala:1795)
at org.scalatest.SuperEngine.runImpl(Engine.scala:521)
at org.scalatest.FlatSpecLike.run(FlatSpecLike.scala:1795)
at org.scalatest.FlatSpecLike.run$(FlatSpecLike.scala:1793)
at org.scalatest.FlatSpec.run(FlatSpec.scala:1685)
at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
at org.scalatest.tools.Runner$.$anonfun$doRunRunRunDaDoRunRun$13(Runner.scala:1346)
at org.scalatest.tools.Runner$.$anonfun$doRunRunRunDaDoRunRun$13$adapted(Runner.scala:1340)
at scala.collection.immutable.List.foreach(List.scala:389)
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1340)
at org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24(Runner.scala:1031)
at org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24$adapted(Runner.scala:1010)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1506)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1010)
at org.scalatest.tools.Runner$.run(Runner.scala:850)
at org.scalatest.tools.Runner.run(Runner.scala)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:131)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)

如果我想跳过测试并且不想回退到标签,我还能做什么?

最佳答案

你也可以把ignore而不是 in - 因此您也可以忽略带有“文本”的测试用例。

这里有一个例子:

  "After running the code" should "be true" ignore {
assert(???)
}
it should "be true in any case" ignore {
assert(???)
}

关于scala - 如何跳过 FlatSpec 中的测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49897247/

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