Skip to content

Multi-line string contains output usability #158

Description

@mkobit

Example:

import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import strikt.api.expectThat
import strikt.assertions.contains

internal class Mk {
  companion object {
    private val S = """
      first line
      second line
      third line
    """.trimIndent()
  }
  @Test
  internal fun `assertj contains`() {
    Assertions.assertThat(S)
      .contains("fourth line")
  }

  @Test
  internal fun `strikt contains`() {
    expectThat(S)
      .contains("fourth line")
  }
}

AssertJ output

Expecting:
java.lang.AssertionError: 
Expecting:
 <"first line
second line
third line">
to contain:
 <"fourth line"> 

Strikt output

org.opentest4j.AssertionFailedError: ▼ Expect that "first line second line third line":
  ✗ contains "fourth line" : found "first line second line third line"

I find the AssertJ a bit more readable in that he multi line text is formatted that way in the assertion error output.

Also, in the strikt output the "first line second line third line" piece is duplicated when it might not have to be.

Maybe:

  • Improve subject line to have improved formatting for multi line string contexts
  • Reduce duplication of subject in assertions messages

WDYT?

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions