Skip to content

costinm92/kotlin-testing-rx-streams-with-step-verifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kotlin testing rx streams with StepVerifier

Overview

Unit testing is a software testing method by which individual units of source code are tested to determine whether they are fit for use.

What is StepVerifier?

StepVerifier is an instrument for testing reactive streams. It provides a declarative way of creating a verifiable script for an async Publisher sequence, by expressing expectations about the events that will happen upon subscription. The verification must be triggered after the terminal expectations (completion, error, cancellation) have been declared, by calling one of the verify() methods.

In short, StepVerifier is an instrument that the developers can use to tests reactive streams.

Methods

  • Create a StepVerifier for a Publisher: use create(Publisher) or withVirtualTime(Supplier)
  • Set up individual value expectations: use expectNext, expectNextMatches(Predicate), assertNext(Consumer), expectNextCount(long) or expectNextSequence(Iterable).
  • Trigger subscription actions during the verification: use thenRequest(long) or thenCancel().
  • Finalize the test scenario: use expectComplete(), expectError(), expectError(Class), expectErrorMatches(Predicate), or thenCancel().
  • Trigger the verification of the resulting StepVerifier on its Publisher: use either verify() or verify(Duration).
  • If any expectations failed, an AssertionError will be thrown indicating the failures.

Example

In this example, we will look at some of the methods listed above

Gradle dependency

We need a testCompile dependency in order to be able to use StepVerifier in our tests:

testCompile(group = "io.projectreactor", name = "reactor-test", version = "3.2.3.RELEASE")

Model

For this example, we have created a dummy model class that will be used in our tests:

data class Person(
    val firstName: String,
    val lastName: String
)

Writing the tests

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages