largeString shouldMatchFile "workflow.yaml"
See original GitHub issuePlease describe the feature you’d like to see including any solutions in mind if you have any
To compare very large strings, it’s easier to write the expected content in a separate file.
class IntegrationTest : FunSpec({
setupShouldMatchFile(
baseDirectory = File("src/test/resources/integration"),
normalize = { it.replace("\r\n", "\n") }, // test shouldn't fail on CI running on windows
)
test("workflowTest : toYaml()") {
workflowTest.toYaml() shouldMatchFile "workflowTest.yaml"
}
}
When the test fails, the error message is:
Files differ in /Users/jmfayard/IdeaProjects/github-actions-kotlin-dsl/library/src/test/resources/integration
Expected: expected/workflowTest.yaml
Actual: actual/workflowTest.yaml
That tells me exactly what I need to use IntelliJ Diff tool, the perfect tool to check what happens and fix it.
The alternative to put the very long string inside the test is ugly
Especially modifying the large expected string is hard.
My implementation is done at https://github.com/krzema12/github-actions-kotlin-dsl/blob/6fc0b3f279ee7372e084545245a08d9e51f36317/library/src/test/kotlin/it/krzeminski/githubactions/kotest/ShouldMatchFile.kt
I fall back to use this shouldBe file.readText()
on the CI (for me GitHub Actions) because there I can’t easily compare the content of the actual and the expected file.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top GitHub Comments
@Kantis
readResource
is nice ; when I use IntelliJ diffing tool, I do not only see the diff, I can also directly edit the expected file, accepting or rejecting chunks of the diff. For large files that’s quite convenient.Hi, I’ve submitted a PR for this but I was wondering how to make the
Expected
file path clickable in IntelliJ. The only way that I found is to get absolute path of that resource file, but it points to thebuild
directory which make no sense in scope of editing this in diff window.Also
Actual
file is not clickable on dry run (when that file doesn’t exist in build directory).