Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.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
Scalatest匹配选项_Scala_Scalatest - Fatal编程技术网

Scalatest匹配选项

Scalatest匹配选项,scala,scalatest,Scala,Scalatest,我有一个简单的测试: test("transform /home into Array(/home)") { val path = "/home" val expected: Option[Array[String]] = Some(Array("/home")) val actual: Option[Array[String]] = luceneService.buildCategoryTree(path) actual shouldEqual expected

我有一个简单的测试:

test("transform /home into Array(/home)") {
    val path = "/home"
    val expected: Option[Array[String]] = Some(Array("/home"))
    val actual: Option[Array[String]] = luceneService.buildCategoryTree(path)
    actual shouldEqual expected
}
我得到了这个失败:

Some(Array("/home")) did not equal Some(Array("/home"))
这怎么可能

据我所知,我应该能够在测试中使用选项

如果我把测试改为

actual.get shouldEqual expected.get
它在sclatest中通过

有一节说:

您可以使用ScalaTest的相等、空、已定义、, 和包含语法。例如,如果您希望检查 选项为“无”,您可以编写以下任意内容:

所以用你的测试抱歉我没有德卢塞恩的对象,我也认为这是一些

不幸的是,当前的实现无法正确地执行 如果数组位于另一个容器中,则理解数组相等性,例如 设置为[Array[Int]]。例如,我本以为会出现以下情况 要通过测试,而不是抛出TestFailedException:

导入org.scalatest_

class SetSuite extends FunSuite with Matchers {

  test("transform /home into Array(/home)") {
    val path = "/home"
    val expected: Option[Array[String]] = Some(Array("/home"))
    val actual: Option[Array[String]] = Some(Array(path))
    actual shouldEqual expected
  }
}

[info] SetSuite:
[info] - transform /home into Array(/home) *** FAILED ***
[info]   Some(Array("/home")) did not equal Some(Array("/home")) (TestScalaTest.scala:9)
[info] Run completed in 335 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 0, failed 1, canceled 0, ignored 0, pending 0
[info] *** 1 TEST FAILED ***
[error] Failed tests:
[error]     SetSuite
[error] (test:test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 11 s, completed Mar 17, 2016 12:26:25 AM
因此,对于测试,让我们使用

import org.scalatest._

class SetSuite extends FunSuite with Matchers {

  test("transform /home into Array(/home)") {
    val path = "/home"
    val expected: Option[Array[String]] = Some(Array("/home"))
    val actual: Option[Array[String]] = Some(Array(path))
    actual should contain (Array("/home"))
  }
}

[info] SetSuite:
[info] - transform /home into Array(/home)
[info] Run completed in 201 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 2 s, completed Mar 17, 2016 12:33:01 AM
在最困难的时候

有一节说:

您可以使用ScalaTest的相等、空、已定义、, 和包含语法。例如,如果您希望检查 选项为“无”,您可以编写以下任意内容:

所以用你的测试抱歉我没有德卢塞恩的对象,我也认为这是一些

不幸的是,当前的实现无法正确地执行 如果数组位于另一个容器中,则理解数组相等性,例如 设置为[Array[Int]]。例如,我本以为会出现以下情况 要通过测试,而不是抛出TestFailedException:

导入org.scalatest_

class SetSuite extends FunSuite with Matchers {

  test("transform /home into Array(/home)") {
    val path = "/home"
    val expected: Option[Array[String]] = Some(Array("/home"))
    val actual: Option[Array[String]] = Some(Array(path))
    actual shouldEqual expected
  }
}

[info] SetSuite:
[info] - transform /home into Array(/home) *** FAILED ***
[info]   Some(Array("/home")) did not equal Some(Array("/home")) (TestScalaTest.scala:9)
[info] Run completed in 335 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 0, failed 1, canceled 0, ignored 0, pending 0
[info] *** 1 TEST FAILED ***
[error] Failed tests:
[error]     SetSuite
[error] (test:test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 11 s, completed Mar 17, 2016 12:26:25 AM
因此,对于测试,让我们使用

import org.scalatest._

class SetSuite extends FunSuite with Matchers {

  test("transform /home into Array(/home)") {
    val path = "/home"
    val expected: Option[Array[String]] = Some(Array("/home"))
    val actual: Option[Array[String]] = Some(Array(path))
    actual should contain (Array("/home"))
  }
}

[info] SetSuite:
[info] - transform /home into Array(/home)
[info] Run completed in 201 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 2 s, completed Mar 17, 2016 12:33:01 AM

看起来匹配器有问题。 使用Seq而不是数组工作:


看起来匹配器有问题。 使用Seq而不是数组工作:


这是scalatest关于数组的问题。如果将数组转换为向量或列表,同样的测试也可以正常工作

这是scalatest对数组的问题。如果你将数组转换为向量或列表,同样的测试也可以正常工作

我认为,如果你只是解释问题所在,而不是仅仅粘贴一些输出作为你知道问题所在的证据,那会更有帮助:/我现在指出了问题,并解决了问题,谢谢你的纠正,如果您只是解释问题所在,而不是仅仅粘贴一些输出作为您知道问题所在的证据,这将更有帮助:/I现在指出了问题,并进行了解决,谢谢您的更正