我的团队正在使用Scala,IntelliJ和Maven。
在我需要的当前模块的一些测试中,我正在处理内部测试执行顺序很重要。
由于某些原因,在IntelliJ中使用JUnit或ScalaTest运行相同的测试会影响执行顺序。
例如,以下测试:
package com.liveperson.lpbt.hadoop.monitoring.temp
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, BeforeAndAfterAll}
@RunWith(classOf[JUnitRunner])
class TempTest extends FunSuite with BeforeAndAfterAll{
println("start TempTest")
override def beforeAll(){
println("beforeAll")
}
override def afterAll(){
println("afterAll")
}
test("test code"){
println("in test code")
}
println("end TempTest")
}
使用JUnit运行时,上面的代码打印出来:
start TempTest
end TempTest
in test code
beforeAll
afterAll
使用ScalaTest运行时,上面的代码打印出来:
start TempTest
end TempTest
beforeAll
in test code
afterAll
有人知道如何编写这样的测试来确保ScalaTests和JUint中的执行顺序吗? 另外,如何在IntelliJ中切换它们?
答案 0 :(得分:0)
您能详细说明如何获得JUnit输出吗?我刚试过从命令行做你的课并获得预期的输出(与你的不同):
Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/ org.scalatest.run TempTest start TempTest end TempTest Discovery starting. Discovery completed in 19 milliseconds. Run starting. Expected test count is: 1 beforeAll TempTest: in test code - test code afterAll Run completed in 140 milliseconds. Total number of tests run: 1 Suites: completed 1, aborted 0 Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0 All tests passed. Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/ org.junit.runner.JUnitCore TempTest JUnit version 4.8.1 Could not find class: TempTest Time: 0.001 OK (0 tests) Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/:. org.junit.runner.JUnitCore TempTest JUnit version 4.8.1 start TempTest end TempTest beforeAll .in test code afterAll Time: 0.078 OK (1 test)