Skip to content

Martini Assertion Functions

Overview

Martini Assertion Functions let you verify that a value, condition, or data model produced by a workflow test matches what you expect. Each function throws an AssertionError with your custom message when the check fails, which stops the test's node graph before it can reach the final success = true Map node.

What You Will Learn

  • How equality and identity assertions (assertEquals, assertNotEquals, assertSame, assertNotSame) differ
  • How to assert on a condition or a null value with assertTrue/assertFalse and assertNull/assertNotNull
  • How the container assertions (assertContains, assertContainsAll, assertContainsAny, assertContainsNone, assertEmpty, assertNotEmpty) behave across collections, maps, strings, and arrays
  • How to check that a data model has a given property with assertHasProperty

When To Use This

Use Martini Assertion Functions when you need to:

  • Confirm a workflow test's system under test (SUT) returned the exact value, object reference, or null/non-null result you expect
  • Check that a collection, map, string, or array produced by the SUT contains (or doesn't contain) specific values, or is empty/not empty
  • Verify that a data model output by the SUT has a particular property set, for example after a mapping or transformation step

Prerequisites

Assertion functions are listed under the TESTING folder in the Functions view. In content assist, search for them using the assert keyword instead of AssertionMethods.

Equality and Identity Assertions

Use these assertions to compare two values or two object references on the invoke node's output properties.

Function Checks Throws when
assertEquals(expected, actual, message) expected and actual are equal The values are not equal
assertNotEquals(unexpected, actual, message) unexpected and actual are not equal The values are equal
assertSame(expected, actual, message) expected and actual refer to the same object instance The references don't point to the same instance
assertNotSame(unexpected, actual, message) unexpected and actual refer to different object instances The references point to the same instance

Reach for assertEquals/assertNotEquals when comparing values such as strings, numbers, or data model property values. Reach for assertSame/assertNotSame only when you specifically need to confirm object identity rather than equivalent content — for example, confirming a cached object was reused rather than rebuilt.

Condition and Null Assertions

Use these assertions to check a boolean condition, or whether a value is null.

Function Checks Throws when
assertTrue(condition, message) condition is true condition is false
assertFalse(condition, message) condition is false condition is true
assertNull(value, message) value is null value is not null
assertNotNull(value, message) value is not null value is null

assertTrue/assertFalse are the most general-purpose assertions — use them for any boolean expression you can build in the Invoke Function node's Data Mapper Panel, such as comparing a number against a threshold. Like all assertion functions, these are called from an Invoke Function node, which also lets you pass a set expression as a parameter instead of mapping a declared property. assertNull/assertNotNull are useful for confirming a SUT correctly omitted (or populated) an optional property.

Container Assertions

Use these assertions to check membership and emptiness on a Collection, Map, CharSequence (string), or array. The following table shows what "contains" means for each supported container type:

Container type What's checked
Collection Membership via contains()
Map Membership among the map's values only — keys aren't checked
CharSequence Whether the expected value appears as a substring
Array Whether an equal element exists among the array's elements
Function Checks Throws when
assertContains(container, expectedValue, message) container contains expectedValue container is missing expectedValue
assertContainsAll(container, expectedValues, message) container contains every value in expectedValues container is missing any value in expectedValues
assertContainsAny(container, expectedValues, message) container contains at least one value from expectedValues container contains none of expectedValues
assertContainsNone(container, unexpectedValues, message) container contains none of unexpectedValues container contains any value from unexpectedValues
assertEmpty(value, message) value has no elements, entries, or characters value is not empty
assertNotEmpty(value, message) value has one or more elements, entries, or characters value is empty

container/value is required and must not be null for any of these six functions — pass a non-null Collection, Map, CharSequence, or array, or the assertion throws an IllegalArgumentException instead of evaluating your check. assertContainsAll, assertContainsAny, and assertContainsNone also require a non-null expectedValues/unexpectedValues list of the values to check for.

Use assertContains and assertContainsNone when checking a single value's presence or absence. Reach for assertContainsAll when every expected value must be present (for example, confirming a response includes every required field) and assertContainsAny when only one of several acceptable values needs to be present.

Data Model Assertions

assertHasProperty(dataModel, propertyName, message) asserts that a data model instance contains a named property, throwing an AssertionError if propertyName isn't present on dataModel. dataModel must not be null.

Use this assertion to confirm a dynamically added property is present on a data model whose Allow Extra Properties setting is enabled. Such properties can be added to the model at runtime and aren't declared at development time, so they don't appear as mappable properties in the Data Mapper Panel — assertHasProperty lets you verify one was actually set by the SUT before asserting on its value with another function such as assertNotNull or assertEquals.

Helpful Resources

  • Workflow Tests — Create workflow tests and follow the required success output contract that assertion functions help you satisfy
  • Testing in Martini Designer — Test Explorer basics for running and reviewing workflow tests
  • Invoke Function Node — The node type used to call an assertion function
  • Data Models — Reference for the data model objects assertHasProperty inspects
  • Community Q&A: Martini Community
    Have a question? Post or search it here.