Adam S
08/21/2024, 10:11 AMstringA shouldBe stringB
fails the error floods the logs with the string content, obscuring the actual failure. Is there a better way?
If it helps, I can save the strings to files.Klitos Kyriacou
08/21/2024, 11:41 AMclass MyTest : FreeSpec({
"test" {
val s = buildString {
repeat(1000) { append(Random.nextInt(' '.code, 127).toChar()) }
}
assertThat((s + 'a' + s).toCharArray()).isEqualTo((s + s).toCharArray())
}
})
Result:
org.opentest4j.AssertionFailedError: expected:<...a', 'D', 'A', 'e', '[]U', 'n', 'L', '*', '...> but was:<...a', 'D', 'A', 'e', '[a', ']U', 'n', 'L', '*', '...>
The difference is highlighted by the `[]`s.
Second, we can use a utility such as StringUtils.difference
from Apache commons-lang3.christophsturm
08/21/2024, 12:52 PMAlex Kuznetsov
08/21/2024, 2:31 PMAlex Kuznetsov
08/21/2024, 2:34 PMval line = "The quick brown fox jumps over the lazy dog"
"find one match" {
val actual = describePartialMatchesInString("brown fox jumps over", line)
actual.partialMatchesList shouldBe "Substring[0] of expected with indexes: 0..19 matched a substring of actual with indexes: 10..29"
actual.partialMatchesDescription shouldBe
"""The quick brown fox jumps over the lazy dog
|----------++++++++++++++++++++-------------""".trimMargin()
}
Alex Kuznetsov
08/21/2024, 2:35 PMAlex Kuznetsov
08/21/2024, 2:38 PMAdam S
08/21/2024, 2:39 PMAlex Kuznetsov
08/21/2024, 2:41 PMAlex Kuznetsov
08/21/2024, 2:41 PMAlex Kuznetsov
08/21/2024, 2:43 PMchristophsturm
08/21/2024, 2:44 PMAlex Kuznetsov
08/21/2024, 2:44 PMAdam S
08/21/2024, 2:46 PMCan you DM some strings?Just run
./gradlew :foo-subproject:kotlinDslAccessorsReport
:)christophsturm
08/21/2024, 2:46 PMchristophsturm
08/21/2024, 2:47 PMKlitos Kyriacou
08/21/2024, 2:48 PMAdam S
08/21/2024, 2:52 PMAlex Kuznetsov
08/21/2024, 2:52 PMgit diff
should be able to handlechristophsturm
08/21/2024, 2:59 PMAdam S
08/21/2024, 3:02 PMAdam S
08/21/2024, 3:02 PMDEFAULT_MESSAGE_LENGTH_THRESHOLD = 10_000
Alex Kuznetsov
08/21/2024, 3:02 PMassertEquals
is a JUnit method, right?christophsturm
08/21/2024, 3:03 PMAlex Kuznetsov
08/21/2024, 3:03 PMchristophsturm
08/21/2024, 3:05 PMAlex Kuznetsov
08/21/2024, 3:10 PMAlex Kuznetsov
08/21/2024, 4:54 PMKlitos Kyriacou
08/21/2024, 5:08 PMAlex Kuznetsov
08/21/2024, 5:28 PMchristophsturm
08/21/2024, 5:31 PMdo you have any ideas on what to improve in kotest ’s collections matchersI’m not using kotest assertions so I have no idea what to improve there. I think there should be a good diffing library that is not tied to an assertion lib and can figure out the best way to show changes in 2 objects graphs. I would probably start with a test suite where i just have test data and expectations what the perfect way to show the difference between them would be.
christophsturm
08/21/2024, 5:40 PMAlex Kuznetsov
08/22/2024, 1:22 PMchristophsturm
08/22/2024, 1:47 PMdave08
09/12/2024, 11:06 AM