How to get intellij to offer a text diff comparison on failed tests

Spread the love

Question Description

I’m writing a Scala test with some ScalaTest matchers.

When my test fails, intellij says something like

{"count":3,"pagination":{"offset":0,"limit":100},"content":{"uri":"http://locahost.com/catalogue/content?order=Query&id=18,20,19"},"list":[{"id":"18","position":27},{"id":"20","position":341},{"id":"19","position":33}]} was not equal to {"count":3,"pagination":{"offset":0,"limit":100},"content":{"uri":"http://locahost.com/catalogue/content?order=Query&id=18,20,19"},"list":[{"id":"18","timestamp":"2015-01-28T11:55:44.494Z","content":"Episode","position":27},{"id":"20","timestamp":"2015-01-19T11:55:44.494Z","content":"Program","position":341},{"id":"19","timestamp":"2015-01-17T11:55:44.494Z","content":"Episode","position":33}]}
org.scalatest.exceptions.TestFailedException: {"count":3,"pagination":{"offset":0,"limit":100},"content":{"uri":"http://locahost.com/catalogue/content?order=Query&id=18,20,19"},"list":[{"id":"18","position":27},{"id":"20","position":341},{"id":"19","position":33}]} was not equal to {"count":3,"pagination":{"offset":0,"limit":100},"content":{"uri":"http://locahost.com/catalogue/content?order=Query&id=18,20,19"},"list":[{"id":"18","timestamp":"2015-01-28T11:55:44.494Z","content":"Episode","position":27},{"id":"20","timestamp":"2015-01-19T11:55:44.494Z","content":"Program","position":341},{"id":"19","timestamp":"2015-01-17T11:55:44.494Z","content":"Episode","position":33}]}
at    org.scalatest.MatchersHelper$.newTestFailedException(MatchersHelper.scala:160)
at org.scalatest.Matchers$ShouldMethodHelper$.shouldMatcher(Matchers.scala:6231)
at org.scalatest.Matchers$AnyShouldWrapper.should(Matchers.scala:6265)
...

However, intellij does not give me the handy see difference in the text feature.

I thought it might be because I’m comparing 2 objects

  val responseBody = responseAs[JsValue]
  responseBody should be(viewingByAccountIdResponseJson)

but changing it to

assert(responseBody.toString() === viewingByAccountIdResponseJson.toString())

Does not allow me to do a text comparison either.

Is there any way to configure intellij to do this?

(I’m currently using a FlatSpec with Matchers)

Note: This is related to this question
Formatting output so that Intellij Idea shows diffs for two texts

However, even using the syntax recommended that intellij might pick up, it does not work.

Practice As Follows

I see this is not possible at the moment and as of the current moment in time, is a feature request:

https://youtrack.jetbrains.com/issue/SCL-4867

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.