有人可以解释我的测试报告中会出现这样的句子吗?
" List(数组(109,121,75,101,121))不等于List(数组(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("")
}
}
}
答案 0 :(得分:2)
数组上的等式仅定义为引用相等(如Java中)。因此,您的测试失败。您可以使用java.util.Arrays.equals
检查两个数组的相等性。