sscarduzio
sscarduzio

Reputation: 6188

ScalaTest does not pass even if conditions are verified

Can anybody explain how sentences like this can appear in my test report?

"List(Array(109, 121, 75, 101, 121)) was not equal to List(Array(109, 121, 75, 101, 121))"

Here is the full output

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 ***

These are my tests in code:

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("")
    }
  }
}

Upvotes: 0

Views: 400

Answers (1)

drexin
drexin

Reputation: 24403

Equality on arrays is only defined as reference equality (like in Java). Therefore your test fails. You can check the equality of two arrays with java.util.Arrays.equals.

Upvotes: 2

Related Questions