dimanche 2 juin 2019

Should I re-implement the logic in property based test?

Let's say there is a function to determine if a button should be visible.

fun isButtonVisible(fitlers: List<Filters>, results: List<Shop>, isLoading: Boolean) {
  return fitlers.isNotEmpty() && results.isEmpty() && !isLoading
}

Now I would like to test this function using PBT like:

"the button should be visible if filters is not empty and results is empty and is not loading" {
  forAll { filters: List<Filters>, results: List<Shop>, isLoading: Boolean ->
    val actual = isButtonVisible(filters, results, isLoading)

    // Here re-implement the logic
    val expected = filters.isNotEmpty() && results.isEmpty() && !isLoading

    assertThat(actual).isEqual(expected)
  }
}

It seems that I just re-implement the logic again in my test, is this correct?

Aucun commentaire:

Enregistrer un commentaire