strikt icon indicating copy to clipboard operation
strikt copied to clipboard

.any{ } does not print its condition if its subject collection is empty

Open MartinHaeusler opened this issue 5 years ago • 1 comments

Self-contained Test Case:

import org.junit.Test
import strikt.api.expectThat
import strikt.assertions.any
import strikt.assertions.isNotEmpty

class AnyTest {

    @Test
    fun anyTest() {
        val strings = listOf<String>()
        expectThat(strings).any { get { trim() }.isNotEmpty() }
    }

}

Actual output:

org.opentest4j.AssertionFailedError: ▼ Expect that []:
  ✗ at least one element matches:

Note that at least one element matches: shows nothing after the :. This can be quite confusing if you only see the output and don't have the test source code to read in parallel.

To be perfectly clear on this: I'm absolutely fine with the fact that the any assert fails if the subject collection is empty. I'd just like to see the error message improved.

Expected output (or something along these lines):

org.opentest4j.AssertionFailedError: ▼ Expect that []:
  ✗ at least one element matches:
      ✗ trim() is not empty

It's working fine for non-empty subject collections though.

Strikt version: 0.24.0

MartinHaeusler avatar Apr 16 '20 13:04 MartinHaeusler

Relates to #8

robfletcher avatar May 11 '20 17:05 robfletcher