Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何在IntelliJ idea中运行scala ScalaTest?_Unit Testing_Scala_Intellij Idea_Scalatest - Fatal编程技术网

Unit testing 如何在IntelliJ idea中运行scala ScalaTest?

Unit testing 如何在IntelliJ idea中运行scala ScalaTest?,unit-testing,scala,intellij-idea,scalatest,Unit Testing,Scala,Intellij Idea,Scalatest,我试图在Intellij IDEA(最新社区构建,使用最新的scala插件)中运行scala flatspec测试,但我不断收到“空测试套件”错误 我试着在右键单击时使用正常的“运行”菜单,但它不起作用。我还尝试创建一个新的ScalaTest配置,但运行程序仍然没有进行测试 我能够在单元中使用JScalaTest,但我更喜欢使用flatspec语法 更新:用@RunWith(classOf[JUnitRunner])注释类也没有帮助 谢谢 class SampleTestSpec extends

我试图在Intellij IDEA(最新社区构建,使用最新的scala插件)中运行scala flatspec测试,但我不断收到“空测试套件”错误

我试着在右键单击时使用正常的“运行”菜单,但它不起作用。我还尝试创建一个新的ScalaTest配置,但运行程序仍然没有进行测试

我能够在单元中使用JScalaTest,但我更喜欢使用flatspec语法

更新:用
@RunWith(classOf[JUnitRunner])
注释类也没有帮助

谢谢

class SampleTestSpec extends FlatSpec with ShouldMatchers {
    "test" should "fail" in {
        "this" should equal ("that")
    }
}
更新:从ScalaTest切换到Spec,解决了问题。我仍然喜欢ScalaTest和FlatSpec,但这已经足够好了。有效的代码:

import org.specs._
object SampleTestSpec extends Specification {
    "'hello world' has 11 characters" in {
     "hello world".size must be equalTo(113)
  }
  "'hello world' matches 'h.* w.*'" in {
     "hello world" must be matching("h.* w.*")
  }
}

-teo

好吧,这正是我要做的。

我一直在这样运行它(但是我确实觉得它有点冗长,可能会被删减):


虽然为时已晚,但我遇到了同样的问题(“空测试套件”),在与IDEA bug tracker闲逛之后,我为我的案例找到了解决方案:
我的
scala
版本是
2.9.0-1
scala测试
版本是
2.8.*

将scala测试升级到最新版本(与scala相同)后,它开始工作。

ScalaTest具有所有可能性;我只是用

@RunWith(classOf[JUnitRunner])

如果IntelliJ没有自动拾取测试,则可以执行以下操作:


在运行配置中,创建一个ScalaTest运行配置,并将其“测试种类”设置为“全部在包中”,将其“测试包”设置为包含测试的包。

我能够在IntelliJ中运行FunSuite测试,没有任何问题。但是,我在使用FlatSpec测试时发现,如果使用Ctrl+Shift+F10(即运行所有测试),您需要右键单击或将光标定位在实际的测试类定义上,以便正确执行所有定义的测试并避免令人沮丧的“空测试套件”错误。

这对我来说很有效: 编辑配置->测试种类:包中的所有内容

以防对任何人都有帮助--我对Scala有了新的认识,这是因为我构建测试类的方式。我有

class SomeTests extends FlatSpec {
  def aTest = {
    "This thing when that thing happens" should
    "return some particular response" in {
      // ... test body
    }
  }
}
问题是我用一种方法包装了我的测试,没有意识到在这种情况下测试需要赤裸裸:

class SomeTests extends FlatSpec {

    "This thing when that thing happens" should
    "return some particular response" in {
      // ... test body
    }

}
我在FlatSpec中运行单个测试时也遇到了“空测试套件”问题。我在行为字符串的开头将根本原因缩小为一个空格

例如,在下面的代码中,第一个测试将运行,但第二个测试将不运行(如果单独运行)。这是因为行为字符串“not run”的开头存在空格。如果你把它取下来再运行一次,它应该会工作

import org.scalatest.FlatSpec

class FlatSpecWhiteSpaceTest extends FlatSpec {
    "TestWithNoEmptySpace" should "run" in {
        runTest
    }

    "TestWithEmptySpace" should " not run" in {
        runTest
    }

    def runTest(): Unit = {
        val expectedValue = true
        val actualValue = true
        assert(expectedValue === actualValue)
    }
}
  • IDE:Intellij IDeA 2017.1C
  • Scala版本:2.11.8
  • ScalaTest版本:3.0.1

您必须在文件末尾进行
测试
,然后在测试配置中单击
在Sbt上运行

因此,我从ScalaTest切换到Specification,现在它可以工作了。我可以确认您不需要样板类,也不需要@RunWith:import org.specs.\uObject AuthorizationParserSpec扩展规范{如果你提到实际的版本号,那就太好了。'Latest'是一个移动的目标。重要提示:IntelliJ不会根据情况选择使用ScalaTest编写的测试用例,例如FunSpec。请确保配置“Run Configuration”->“ScalaTest”,以便组合“Test kind”显示“All in package”。我的意思是:以这种方式配置默认值,否则IntelliJ可能会或可能不会以您期望的方式创建新配置。重要信息#2:如果您使用SBT,请使用SBT idea插件为IntelliJ生成配置文件,这些文件在您定义“运行配置”时是必需的.只需右键单击并运行测试,它不工作吗?
import org.scalatest.FlatSpec

class FlatSpecWhiteSpaceTest extends FlatSpec {
    "TestWithNoEmptySpace" should "run" in {
        runTest
    }

    "TestWithEmptySpace" should " not run" in {
        runTest
    }

    def runTest(): Unit = {
        val expectedValue = true
        val actualValue = true
        assert(expectedValue === actualValue)
    }
}