PAssert

Javadoc Javadoc


PAssert is a class included in the Beam Java SDK that is an assertion on the contents of a PCollection. You can use PAssert to verify that a PCollection contains a specific set of expected elements.

Examples

For a given PCollection, you can use PAssert to verify the contents as follows:

PCollection<String> output = ...;

// Check whether a PCollection contains some elements in any order.
PAssert.that(output)
.containsInAnyOrder(
  "elem1",
  "elem3",
  "elem2");

Any code that uses PAssert must link in JUnit and Hamcrest. If you’re using Maven, you can link in Hamcrest by adding the following dependency to your project’s pom.xml file:

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-all</artifactId>
    <version>1.3</version>
    <scope>test</scope>
</dependency>