即使条件得到验证,ScalateTest也不会通过

即使条件得到验证,ScalateTest也不会通过,scala,scalatest,Scala,Scalatest,有人能解释一下我的测试报告中怎么会出现这样的句子吗 “列表(数组(109、121、75、101、121))不等于列表(数组(109、121、75、101、121))” 这是完整的输出 Run starting. Expected test count is: 4 Ws2redisAdapterTest: Ws2redisAdapter - should recognize 1-arity commands - should recognize 2-arity commands *** FAILE

有人能解释一下我的测试报告中怎么会出现这样的句子吗

“列表(数组(109、121、75、101、121))不等于列表(数组(109、121、75、101、121))”

这是完整的输出

Run starting. Expected test count is: 4
Ws2redisAdapterTest:
Ws2redisAdapter
- should recognize 1-arity commands
- should recognize 2-arity commands *** FAILED ***
  List(Array(109, 121, 75, 101, 121)) was not equal to List(Array(109, 121, 75, 101, 121)) (Ws2redisAdapterTest.scala:15)
- should recognize N-arity commands *** FAILED ***
  List(Array(109, 121, 90, 115, 101, 116), Array(48), Array(45, 49)) was not equal to List(Array(109, 121, 90, 115, 101, 116), Array(48), Array(45, 49)) (Ws2redisAdapterTest.scala:
21)
- should throw Exception if an empty string is popped
Run completed in 298 milliseconds.
Total number of tests run: 4
Suites: completed 1, aborted 0
Tests: succeeded 2, failed 2, canceled 0, ignored 0, pending 0
*** 2 TESTS FAILED ***
以下是我的代码测试:

package eu.codesigner.finagle.ws2redis
import org.scalatest._

class Ws2redisAdapterTest extends FlatSpec with Matchers {

  "Ws2redisAdapter" should "recognize 1-arity commands " in {
    val (cmd, args) = Ws2redisAdapter.adaptRedisCommand("INFO")
    cmd should be("INFO")
    args should be(null)
  }

  it should "recognize 2-arity commands " in {
    val (cmd, args) = Ws2redisAdapter.adaptRedisCommand("GET myKey")
    cmd should be("GET")
    args should be(List("myKey".getBytes()))
  }

  it should "recognize N-arity commands " in {
    val (cmd, args) = Ws2redisAdapter.adaptRedisCommand("ZRANGE myZset 0 -1")
        cmd should be("ZRANGE")
        args should be(List("myZset".getBytes(),"0".getBytes(), "-1".getBytes() ))
  }

  it should "throw Exception if an empty string is given" in {
    a[Exception] should be thrownBy {
      Ws2redisAdapter.adaptRedisCommand("")
    }
  }
}

数组上的相等仅定义为引用相等(如在Java中)。因此你的测试失败了。您可以使用
java.util.arrays.equals

检查两个数组的相等性该死,这是新手犯的错误!:)为了仍然能够使用“应该是”,我修改了测试,用map将字节数组转换为字符串。从这个:args应该是(List(“myKey”.getBytes()))到这个:args.map(新字符串())应该是(List(“myKey”))