Hello folks! I have a question with regards to clu...
# kotest
i
Hello folks! I have a question with regards to clues - certain other frameworks, most notably Spock and Hamcrest, when an assertion fails they show the data under test that failed, by default. Is there any way to do this in Kotest without having to wrap everything in clues?
c
Isn't this already the case by default? Do you have an example of a test that doesn't behave like this?
i
Copy code
test("test list contains all elements"){
            val strings = listOf("One", "two", "three")
            strings.shouldContainAll("One", "two", "three","four")
        }
gives me Collection should contain all of ["One", "two", "three", "four"] but was missing ["four"]
to make it into a better example,
Copy code
test("test list contains all elements"){
            val strings = listOf("One", "two", "three","five")
            strings.shouldContainAll("One", "two", "three","four")
        }
kotest tells me that
four
is missing, but I have no clue that a
five
has snuck in
on the other hand `
Copy code
shouldContainExactly
behaves in the expected way
am I the fool here?
c
Well, you're asking Kotest to check that these elements are in the list, you did not say you don't want any other elements
In this case I think what you want to test is
shouldContainExactly
, or even just
shouldBe
i
that's not quite what I want though 🙂 I want feedback on what is there, irrespective of the matcher.
(without having to write clues boilerplate)
c
If you use
assertSoftly
it creates the clue automatically IIRC
i
you mean like so?
Copy code
assertSoftly(strings){
                shouldContainAll("One", "two", "three","four")
            }
c
Yes, I think this prints the entire list? I'm not 100% sure
i
trying it out..
no 😞
c
Ah, it could probably be a feature request to have
assertSoftly
imply
withClue
i
yeah probably.even with
asClue
the output is nowhere near as nice by default as with the
shouldContainExactly
Copy code
[One, two, three, five]
java.lang.AssertionError: [One, two, three, five]
just trying to save keystrokes and frustration 😆
thanks Ivan, appreciate the insight
c
I created an issue for it, please upvote 🙂 https://github.com/kotest/kotest/issues/3418