vertx / io.vertx.ext.unit / TestContext

TestContext

interface TestContext

The test context is used for performing test assertions and manage the completion of the test. This context is provided by vertx-unit as argument of the test case.

Author
Julien Viet

Functions

assertEquals

abstract fun assertEquals(expected: Any, actual: Any): TestContext
abstract fun assertEquals(expected: Any, actual: Any, message: String): TestContext

Assert the expected argument is equals to the actual argument. If the arguments are not equals an assertion error is thrown otherwise the execution continue.

assertFalse

abstract fun assertFalse(condition: Boolean): TestContext
abstract fun assertFalse(condition: Boolean, message: String): TestContext

Assert the specified condition is false. If the condition is true, an assertion error is thrown otherwise the execution continue.

assertInRange

abstract fun assertInRange(expected: Double, actual: Double, delta: Double): TestContext
abstract fun assertInRange(expected: Double, actual: Double, delta: Double, message: String): TestContext

Asserts that the expected double argument is equals to the actual double argument within a positive delta. If the arguments do not satisfy this, an assertion error is thrown otherwise the execution continue.

assertNotEquals

abstract fun assertNotEquals(first: Any, second: Any): TestContext
abstract fun assertNotEquals(first: Any, second: Any, message: String): TestContext

Assert the first argument is not equals to the second argument. If the arguments are equals an assertion error is thrown otherwise the execution continue.

assertNotNull

abstract fun assertNotNull(expected: Any): TestContext
abstract fun assertNotNull(expected: Any, message: String): TestContext

Assert the expected argument is not null. If the argument is null, an assertion error is thrown otherwise the execution continue.

assertNull

abstract fun assertNull(expected: Any): TestContext
abstract fun assertNull(expected: Any, message: String): TestContext

Assert the expected argument is null. If the argument is not, an assertion error is thrown otherwise the execution continue.

assertTrue

abstract fun assertTrue(condition: Boolean): TestContext
abstract fun assertTrue(condition: Boolean, message: String): TestContext

Assert the specified condition is true. If the condition is false, an assertion error is thrown otherwise the execution continue.

async

abstract fun async(): Async

Create and returns a new async object, the returned async controls the completion of the test. Calling the Async#complete() completes the async operation. The test case will complete when all the async objects have their io.vertx.ext.unit.Async#complete() method called at least once. This method shall be used for creating asynchronous exit points for the executed test.

abstract fun async(count: Int): Async

Create and returns a new async object, the returned async controls the completion of the test. This async operation completes when the Async#countDown() is called count times. The test case will complete when all the async objects have their io.vertx.ext.unit.Async#complete() method called at least once. This method shall be used for creating asynchronous exit points for the executed test.

asyncAssertFailure

abstract fun <T : Any> asyncAssertFailure(): Handler<AsyncResult<T>>
abstract fun <T : Any> asyncAssertFailure(causeHandler: Handler<Throwable>): Handler<AsyncResult<T>>

Creates and returns a new async handler, the returned handler controls the completion of the test. When the returned handler is called back with a failed result it completes the async operation. When the returned handler is called back with a succeeded result it fails the test.

asyncAssertSuccess

abstract fun <T : Any> asyncAssertSuccess(): Handler<AsyncResult<T>>

Creates and returns a new async handler, the returned handler controls the completion of the test. When the returned handler is called back with a succeeded result it completes the async operation. When the returned handler is called back with a failed result it fails the test with the cause of the failure.

abstract fun <T : Any> asyncAssertSuccess(resultHandler: Handler<T>): Handler<AsyncResult<T>>

Creates and returns a new async handler, the returned handler controls the completion of the test. When the returned handler is called back with a succeeded result it invokes the resultHandler argument with the async result. The test completes after the result handler is invoked and does not fails. When the returned handler is called back with a failed result it fails the test with the cause of the failure. Note that the result handler can create other async objects during its invocation that would postpone the completion of the test case until those objects are resolved.

exceptionHandler

abstract fun exceptionHandler(): Handler<Throwable>

fail

abstract fun fail(): Unit

Throw a failure.

abstract fun fail(message: String): Unit

Throw a failure with the specified failure message.

abstract fun fail(cause: Throwable): Unit

Throw a failure with the specified failure cause.

get

abstract fun <T : Any> get(key: String): T

Get some data from the context.

put

abstract fun <T : Any> put(key: String, value: Any): T

Put some data in the context.

This can be used to share data between different tests and before/after phases.

remove

abstract fun <T : Any> remove(key: String): T

Remove some data from the context.

strictAsync

abstract fun strictAsync(count: Int): Async

Create and returns a new async object, the returned async controls the completion of the test. This async operation completes when the Async#countDown() is called count times. If Async#countDown() is called more than count times, an IllegalStateException is thrown. The test case will complete when all the async objects have their io.vertx.ext.unit.Async#complete() method called at least once. This method shall be used for creating asynchronous exit points for the executed test.

verify

abstract fun verify(block: Handler<Void>): TestContext

Execute the provided handler, which may contain assertions, possibly from any third-party assertion framework. Any AssertionError thrown will be caught (and propagated) in order to fulfill potential expected async completeness.