Introduction
WebTau
http
module lets you exercise and validate HTTP endpoints. It provides a simplified way to make HTTP calls and validate responsesGroovyJava
private final def livePrice = http.resource("/prices/:ticker").price ... livePrice.of("IBM").waitToBe > 115
> waiting for value of /prices/IBM: price to be greater than 115 > [1/3] executing HTTP GET http://localhost:43675/prices/IBM . header.statusCode equals 200 (0ms) response (application/json): { "price": **100** } . [1/3] executed HTTP GET http://localhost:43675/prices/IBM (3ms) > [3/3] executing HTTP GET http://localhost:43675/prices/IBM . header.statusCode equals 200 (0ms) response (application/json): { "price": ~~120~~ } . [3/3] executed HTTP GET http://localhost:43675/prices/IBM (2ms) . value of /prices/IBM: price greater than 115 (210ms)
GroovyJava
package com.example.tests.junit5 import org.junit.jupiter.api.Test import org.testingisdocumenting.webtau.junit5.WebTau import static org.testingisdocumenting.webtau.WebTauGroovyDsl.* @WebTau class WeatherGroovyTest { @Test void checkWeather() { http.get("/weather") { temperature.shouldBe < 100 } } }
{ "temperature": 88 }
> executing HTTP GET http://localhost:44451/weather . body.temperature less than 100 (0ms) . header.statusCode equals 200 (0ms) response (application/json): { "temperature": ~~88~~ } . executed HTTP GET http://localhost:44451/weather (32ms)