Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

278
Vistas
Is there a Kotest assertion to test if a list contains some element with a given property?

I have two objects that have some features in common that I would like to compare

data class Pet(val colour: String, val owner: Human, val legCount: Int)
data class Car(val colour: String, val owner: Human, val isElectric: Boolean)

I would like to assert that some element in a List<Car> contains an element with the same colour and owner as a given Pet.

Here's a fake code example to illustrate what I'm trying to do:

cars.containsElementSatisfying { car ->
    pet.colour shouldBe car.colour
    pet.owner shouldBe car.owner
}

How might I do this using kotest? I can accomplish the desired functionality using assertJ's anySatisfy assertion.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I found the solution. The "Inspectors" kotest library contains a number of functions similar to assertJ's anySatisfy assertion, in particular the collection functions forAtLeastOne and forAtLeast(k)

Here's example usage:

cars.forAtLeastOne { car -> 
    pet.colour shouldBe car.colour
    pet.owner shouldBe car.owner
}

https://kotest.io/docs/assertions/inspectors.html

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda