Package io.vertx.ext.unit.junit

## Class RunTestOnContext

- java.lang.Object
- - io.vertx.ext.unit.junit.RunTestOnContext

- All Implemented Interfaces:
    `org.junit.rules.TestRule`

      public class RunTestOnContext
      extends Object
      implements org.junit.rules.TestRule

  A JUnit rule that runs tests on a Vert.x context.

  When used as a `Rule` a new context is created for each tested method, the context will be same for the before and after method, but different for all the tested methods.

  When used as a `ClassRule`, a single context is created for all the tested method, the beforeClass and afterClass method will also executed in this context.
  Author:
    Julien Viet

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `RunTestOnContext()` | Create a new rule managing a Vertx instance created with default options.
    `RunTestOnContext​(Future<Vertx> createVertx)` | Create a new rule with an asynchronous supplier for creating a Vert.x instance.
    `RunTestOnContext​(Future<Vertx> createVertx, BiConsumer<Vertx,​Consumer<Void>> closeVertx)` | Create a new rule with an asynchronous supplier and consumer for creating and closing a Vert.x instance.
    `RunTestOnContext​(VertxOptions options)` | Create a new rule managing a Vertx instance created with specified options.
    `RunTestOnContext​(Supplier<Vertx> createVertx)` | Create a new rule with supplier for creating a Vert.x instance.
    `RunTestOnContext​(Supplier<Vertx> createVertx, BiConsumer<Vertx,​Consumer<Void>> closeVertx)` | Create a new rule with supplier/consumer for creating/closing a Vert.x instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `org.junit.runners.model.Statement` | `apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)` |
    `Vertx` | `vertx()` | Retrieves the current Vert.x instance, this value varies according to the test life cycle.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RunTestOnContext

          public RunTestOnContext()

      Create a new rule managing a Vertx instance created with default options. The Vert.x instance is created and closed for each test.

    - #### RunTestOnContext

          public RunTestOnContext​(VertxOptions options)

      Create a new rule managing a Vertx instance created with specified options. The Vert.x instance is created and closed for each test.
      Parameters:
        `options` - the vertx options

    - #### RunTestOnContext

          public RunTestOnContext​(Supplier<Vertx> createVertx)

      Create a new rule with supplier for creating a Vert.x instance. The lambda are invoked for each test.
      Parameters:
        `createVertx` - the create Vert.x supplier

    - #### RunTestOnContext

          public RunTestOnContext​(Supplier<Vertx> createVertx,
                                  BiConsumer<Vertx,​Consumer<Void>> closeVertx)

      Create a new rule with supplier/consumer for creating/closing a Vert.x instance. The lambda are invoked for each test. The `closeVertx` lambda should invoke the consumer with null when the `vertx` instance is closed.
      Parameters:
        `createVertx` - the create Vert.x supplier
        `closeVertx` - the close Vert.x consumer

    - #### RunTestOnContext

          public RunTestOnContext​(Future<Vertx> createVertx)

      Create a new rule with an asynchronous supplier for creating a Vert.x instance. The lambda are invoked for each test.
      Parameters:
        `createVertx` - the asynchronous create Vert.x supplier

    - #### RunTestOnContext

          public RunTestOnContext​(Future<Vertx> createVertx,
                                  BiConsumer<Vertx,​Consumer<Void>> closeVertx)

      Create a new rule with an asynchronous supplier and consumer for creating and closing a Vert.x instance. The lambda are invoked for each test. The `closeVertx` lambda should invoke the consumer with null when the `vertx` instance is closed.
      Parameters:
        `createVertx` - the asynchronous Vert.x supplier
        `closeVertx` - the close Vert.x consumer

  - ### Method Detail

    - #### vertx

          public Vertx vertx()

      Retrieves the current Vert.x instance, this value varies according to the test life cycle.
      Returns:
        the vertx object

    - #### apply

          public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                         org.junit.runner.Description description)

      Specified by:
        `apply` in interface `org.junit.rules.TestRule`