1

I was trying to compare to String Arrays in a JUnit test suite in Scala using assertArrayEquals. It works fine for basic types like Int or Boolean, however it issues the following error when applying it to String:

overloaded method value toString with alternatives: (x$1: Array[Object])String (x$1: Array[Double])String (x$1: Array[Float])String (x$1: Array[Boolean])String (x$1: Array[Byte])String (x$1: Array[Char])String (x$1: Array[Short])String (x$1: Array[Int])String (x$1: Array[Long])String cannot be applied to (Array[String])

This seems weird to me since using the same method in a Java environment works without a problem. Is there a way to circumvent this?

3
  • 1
    Hint: use assertThat(actual, is(whatever)). Works for almost everything. Commented Sep 30, 2016 at 8:42
  • Jep, works like a charm. Thank you! Commented Sep 30, 2016 at 8:48
  • Thanks for the quick accept. Looking forward to "work" with you again ;-) Commented Sep 30, 2016 at 8:58

1 Answer 1

1

My "general" answer: one only needs one assert; and that is assertThat. That assert works with Hamcrest matchers, so typically you write down

assertThat(expected, is(whatever))

And using the wide range of existing hamcrest matchers, you immediately get "expected" results; even for collections and such things.

And if the standard means don't work; writing custom matchers is a straight forward task, too.

So, long story short: just use that assert that simply works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.