Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

414
Views
En REST Assured, ¿cómo puedo verificar si un campo está presente o no en la respuesta?

¿Cómo puedo asegurarme de que mi respuesta, digamos que está en JSON, contiene o no contiene un campo específico?

 when() .get("/person/12345") .then() .body("surname", isPresent()) // Doesn't work... .body("age", isNotPresent()); // ...But that's the idea.

Estoy buscando una manera de afirmar si mi JSON contendrá o no los campos edad y apellido .

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

También puede usar el comparador Hamcrest hasKey() (de la clase org.hamcrest.Matchers ) en cadenas JSON.

 when() .get("/person/12345") .then() .body("$", hasKey("surname")) .body("$", not(hasKey("age")));
over 4 years ago · Santiago Trujillo Report

0

Usando: import static org.junit.Assert.assertThat;

Entonces podría: assertThat(response.then().body(containsString("thingThatShouldntBeHere")), is(false));

over 4 years ago · Santiago Trujillo Report

0

Puedes usar equals (null) así:

.body("surname", equals(null))

Si el campo no existe será nulo

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!