0

I'm currently working with arrays as inputs to my data parameterized test fixtures in ScalaTest and this is what I'm getting:

ArrayIndexOutOfBoundsException was thrown during property evaluation. (SortingSpec.scala:43)
  Message: 2
  Occurred at table row 2 (zero based, not counting headings), which had values (
    Input = [I@17c386de,
    Expected = [I@5af97850
  )

Is there some way to turn this descriptions into something more meaningful?

Thanks

devoured elysium
  • 101,373
  • 131
  • 340
  • 557
  • Not sure what you mean. Just compare the arrays as `IndexedSeq` or similar (by wrapping them). I guess you already use [`inside`](http://www.scalatest.org/user_guide/using_inside) – Gábor Bakos Jan 21 '18 at 12:37
  • Never heard of that `inside`. I can't compare the arrays as IndexedSeq, they are parameters of my testing function, unless I define them as IndexedSeq and just before calling the test methods I convert them to arrays, which would be acceptable but not particularly pretty. – devoured elysium Jan 21 '18 at 13:29
  • You could override `def toString: String` inside the class of the objects. Or if they are immutable convert the class to a case class with a companion object, which will automatically override `toString`. Edit: oh you were talking about `Array`, then Gábor Bakos' solution should do the trick. – 6infinity8 Jan 21 '18 at 13:50
  • Possible duplicate of [How to show custom failure messages in ScalaTest?](https://stackoverflow.com/questions/6451530/how-to-show-custom-failure-messages-in-scalatest) – Don Branson Jan 21 '18 at 14:28

1 Answers1

4

Use withClue to wrap your assertions (as described here: http://www.scalatest.org/user_guide/using_assertions ). It allows you to append arbitrary additional string to the assertion, which is displayed if the assertion fails. To make the content of the arrays more readable, it is advisable to invoke mkString("[", ",", "]") on them, or to simply convert them toList.

Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93