为什么 Scalatest 会混淆输出? [英] Why does scalatest mix up the output?

查看:34
本文介绍了为什么 Scalatest 会混淆输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 sbt 运行我的 scalatest,但输出变得混乱 - scalatest 打印所有测试运行,并向它们发表评论,并在中间的某个地方打印统计数据:

I run my scalatest from sbt, and the output gets mixed up - scalatest prints all the test run, and comments to them, and somewhere in the middle it prints the statistics:

> test
[info] Compiling 1 Scala source to /home/platon/Tor/scala-dojo-02/target/scala-2.9.1/classes...
[info] FunsWithListsTests:
[info] - should return list of labels
[info] - should return the average rating of games belonging to Zenga
[info] - should return the total ratings of all games
[info] - should return the total ratings of EA games *** FAILED ***
[info]   0 did not equal 170 (FunsWithListsTests.scala:35)
[error] Failed: : Total 8, Failed 5, Errors 0, Passed 3, Skipped 0
[info] - should increase all games rating by 10 *** FAILED ***
[error] Failed tests:
[error]     dojo.FunsWithListsTests
[info]   List() did not equal List(Game(Activision,40), Game(Zenga,70), Game(Zenga,20), Game(EA,70), Game(EA,120)) (FunsWithListsTests.scala:40)
[info] - should decrease all Zenga games rating by 10 *** FAILED ***
[info]   List() did not equal List(Game(Activision,30), Game(Zenga,50), Game(Zenga,0), Game(EA,60), Game(EA,110)) (FunsWithListsTests.scala:45)
[info] - should create function to find Activision games *** FAILED ***
[info]   List(Game(Activision,30), Game(Zenga,60), Game(Zenga,10), Game(EA,60), Game(EA,110)) did not equal List(Game(Activision,30)) (FunsWithListsTests.scala:50)
[info] - should return a List of tuples consisting of game label and game *** FAILED ***
[info]   List() did not equal List((ACTIVISION,Game(Activision,30)), (ZENGA,Game(Zenga,60)), (ZENGA,Game(Zenga,10)), (EA,Game(EA,60)), (EA,Game(EA,110))) (FunsWithListsTests.scala:56)
[error] {file:/home/platon/Tor/scala-dojo-02/}default-940f03/test:test: Tests unsuccessful
[error] Total time: 1 s, completed Mar 20, 2012 9:27:13 AM

看来,如果我要积累大量的测试,搜索这些统计数据和失败的测试会变得很痛苦.

It seems that if I would accumulate a great number of tests, searching for those stats and failed tests would become a pain.

有没有办法解决这个问题?

Is there a way to fix this?

推荐答案

在我看来,原因是 SBT 默认情况下并行执行测试,与 maven-surefire-plugin 相同.

It looks to me the reason for that is that SBT by default executes the tests in parallel, the same way maven-surefire-plugin does.

正如 ScalaTest wiki 中所解释的,这可以通过以下方式解决:

As it is explained in ScalaTest wiki, this can be solved by:

禁用并行执行测试默认情况下,sbt 并行运行所有任务.因为每个测试都映射到一个任务,所以默认情况下测试也是并行运行的.要禁用测试的并行执行:

Disable Parallel Execution of Tests By default, sbt runs all tasks in parallel. Because each test is mapped to a task, tests are also run in parallel by default. To disable parallel execution of tests:

parallelExecution in Test := false

这篇关于为什么 Scalatest 会混淆输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆