使用IntelliJ和Maven的ScalaTest和JUnit测试的执行顺序

使用IntelliJ和Maven的ScalaTest和JUnit测试的执行顺序,scala,junit,intellij-idea,scalatest,junit-runner,Scala,Junit,Intellij Idea,Scalatest,Junit Runner,我的团队正在使用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.s

我的团队正在使用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
start TempTest
end TempTest
beforeAll
in test code
afterAll
使用ScalaTest运行时,会打印出上述代码:

start TempTest
end TempTest
in test code
beforeAll
afterAll
start TempTest
end TempTest
beforeAll
in test code
afterAll
有人知道如何编写这样的测试,以确保Scalatest和JUint中的执行顺序吗?
另外,在IntelliJ中如何在它们之间切换?

您能否详细说明如何获得JUnit输出?我刚刚尝试从命令行执行您的类,得到了预期的输出(与您的不同):

Mi Novia:rootsoccer bv$scala-cp~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar\u contents/org.scalatest.run 开始诱惑 结束诱惑 探索开始了。 发现在19毫秒内完成。 开始跑步。预期测试计数为:1 以前 诱人的: 在测试代码中 -测试代码 毕竟 运行在140毫秒内完成。 运行的测试总数:1 套件:已完成1,已中止0 测试:成功1、失败0、取消0、忽略0、挂起0 所有测试都通过了。 Mi Novia:rootsoccer bv$scala-cp~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/org.junit.runner.JUnitCore JUnit版本4.8.1 找不到类:诱惑 时间:0.001 正常(0次测试) Mi Novia:rootsoccer bv$scala-cp~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar\u contents/:。org.junit.runner.JUnitCore诱惑 JUnit版本4.8.1 开始诱惑 结束诱惑 以前 .在测试代码中 毕竟 时间:0.078 正常(1次测试)
您好,您的输出类似于我先前帖子中的第二个输出。正如我之前提到的,我正在使用IntelliJ和两种可能的不同方式运行测试。我还尝试使用Maven在命令行中运行。我过去直接在命令行中运行的命令如上面的响应所示。我现在正在登机,但稍后将在IntelliJ中尝试此功能,看看是否可以重现您的问题。