我有一个可能需要长时间运行的测试分级测试:
test("a long running test") {
failAfter(Span(60, Seconds)) {
// ...
}
}
即使测试在超时限制内完成,其运行时间对于运行测试的人来说也是有价值的。我如何测量并显示这个的运行时间singlescalatest 输出中的特定测试?
Update:目前我用自己的函数测量运行时间,就像 r.v 的答案一样。我想知道是否分级测试已经提供此功能。
the -oD
选项将给出测试的持续时间。例如,我在 build.sbt 中使用以下内容。
testOptions in Test += Tests.Argument("-oD")
EDIT:
您还可以将以下内容用于单独运行:
> test-only org.acme.RedSuite -- -oD
See http://www.scalatest.org/user_guide/using_scalatest_with_sbt http://www.scalatest.org/user_guide/using_scalatest_with_sbt.
此外,您可以为一般时间测量定义以下函数:
def time[T](str: String)(thunk: => T): T = {
print(str + "... ")
val t1 = System.currentTimeMillis
val x = thunk
val t2 = System.currentTimeMillis
println((t2 - t1) + " msecs")
x
}
并在任何地方使用它(不依赖于 ScalaTest)
test("a long running test") {
time("test running"){
failAfter(Span(60, Seconds)) {
// ...
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)