When comparing two strings with #kotlintest with the test like this:
"compare two strings" {
"1: one\n2: two\n3: three".shouldBe("1: one1\n22: two\n3: three")
}
, the output looks like this:
expected: "1: one1
22: two
3: three" but was: "1: one
2: two
3: three"
org.opentest4j.AssertionFailedError: expected: "1: one1
22: two
3: three" but was: "1: one
2: two
3: three"
Even with such a short string - it's quite hard to spot, what exactly differs between those two strings. And it's much harder if comparing longer strings, or object attributes, as the result becomes just one long scrollable line.
However - we are all very used to read the "diff" - with its +/- lines, and colors, which instantly allow us to spot the difference.
For example, here's the result of the same assert, when ran by rspec
(test lib for ruby):
expected: "1: one\n22: two\n3: three"
got: "1: one\n2: two\n3: three"
(compared using ==)
Diff:
@@ -1,4 +1,4 @@
1: one
-22: two
+2: two
3: three
As you can see - it helps me in two ways.
First - it puts both strings right under each other so that I can spot character level differences.
Secondly, it shows nice diff
with our familiar coloring so that I instantly see what's not different, and what's different.
Is there a way to achieve some test result comparison which would be similar, and give similar benefits to quickly spot the difference?
I tried KotlinTest and JUnit5 - both comparison results are very "horizontally scrollable in one line". Maybe in some other Kotlin test frameworks?
Thanks!