Should

WebTau provides two ways to assert values: should and waitTo . They work for business logic testing, HTTP, Browser, and other layers. Methods accept a matcher as a second parameter:WebTau provides console output for all the matching it does, regardless of whether it fails or passes.Use should to assert a value using a matcher. One of the most common matchers is equal . In WebTau equal is a universal matcher that you will learn about matchers/universal-compare later. Groovy def errorMessage = generateErrorMessage() errorMessage.should == "insufficient disk space" // string and string equality comparison Check matchers/import-and-dependencies Import And Dependencies for prerequisites. Java String errorMessage = generateErrorMessage(); actual(errorMessage).should(equal("insufficient disk space")); // string and string equality comparison Check matchers/import-and-dependencies Import And Dependencies for prerequisites. . [value] equals "insufficient disk space" (0ms) Use shouldBe alias to make a better flow with matchers like greaterThan : Groovy def numberAsText = "200" numberAsText.shouldBe > 150 // text and number relative comparison Java String numberAsText = "200"; actual(numberAsText).shouldBe(greaterThan(150)); // text and number relative comparison

WaitTo

Use waitTo to wait for a value to eventually match a matcher. Groovy actual(liveValue(this::consumeMessage)).waitTo == "message we wait for" Java actual(liveValue(this::consumeMessage)).waitTo(equal("message we wait for")); > waiting for [value] to equal "message we wait for" . [value] equals "message we wait for" (200ms) Use waitToBe alias to make a better flow with matchers like greaterThan : Groovy actual(liveValue(this::countRecords)).waitToBe >= 5 Java actual(liveValue(this::countRecords)).waitToBe(greaterThanOrEqual(5));

Negative Matching

Both should and waitTo have negative forms: Groovy def errorMessage = generateErrorMessage() errorMessage.shouldNot == "completed" . [value] doesn't equal "completed" (0ms) Java String errorMessage = generateErrorMessage(); actual(errorMessage).shouldNot(equal("completed")); . [value] doesn't equal "completed" (0ms) Groovy actual(liveValue(this::consumeMessage)).waitToNot == "duplicate" > waiting for [value] to not equal "duplicate" . [value] doesn't equal "duplicate" (0ms) Java actual(liveValue(this::consumeMessage)).waitToNot(equal("duplicate")); > waiting for [value] to not equal "duplicate" . [value] doesn't equal "duplicate" (0ms)

Failure Output

Above you saw how WebTau outputs matched information. In case of failed assertion WebTau outputs additional information about the actual value. Groovy values.should == [ 1, "teasing", [key1: "hello", key2: "work"]] > expecting code to throw exception java.lang.AssertionError X failed expecting [value] to equal [1, "teasing", {"key1": "hello", "key2": "work"}]: [value][1]: actual: "testing" <java.lang.String> expected: "teasing" <java.lang.String> ^ [value][2].key2: actual: "world" <java.lang.String> expected: "work" <java.lang.String> ^ (1ms) [1, **"testing"**, {"key1": "hello", "key2": **"world"**}] . code thrown java.lang.AssertionError (2ms) Java actual(values).should(equal(Arrays.asList( 1, "teasing", map("key1", "hello", "key2", "work")))); > expecting code to throw exception java.lang.AssertionError X failed expecting [value] to equal [1, "teasing", {"key1": "hello", "key2": "work"}]: [value][1]: actual: "testing" <java.lang.String> expected: "teasing" <java.lang.String> ^ [value][2].key2: actual: "world" <java.lang.String> expected: "work" <java.lang.String> ^ (1ms) [1, **"testing"**, {"key1": "hello", "key2": **"world"**}] . code thrown java.lang.AssertionError (2ms)