Package io.vertx.ext.unit
Interface TestSuite
-
public interface TestSuite
A named suite of test cases that are executed altogether. The suite suite is created with thecreate(String)
and the returned suite contains initially no tests. The suite can declare a callback before the suite withbefore(io.vertx.core.Handler)
or after the suite withafter(io.vertx.core.Handler)
. The suite can declare a callback before each test withbeforeEach(io.vertx.core.Handler)
or after each test withafterEach(io.vertx.core.Handler)
. Each test case of the suite is declared by calling thetest(String, io.vertx.core.Handler)
method.- Author:
- Julien Viet
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description TestSuite
after(Handler<TestContext> callback)
Set a callback executed after the tests.TestSuite
afterEach(Handler<TestContext> callback)
Set a callback executed after each test and before the suiteafter
callback.TestSuite
before(Handler<TestContext> callback)
Set a callback executed before the tests.TestSuite
beforeEach(Handler<TestContext> callback)
Set a callback executed before each test and after the suitebefore
callback.static TestSuite
create(Object testSuiteObject)
Create and return a new test suite configured after thetestSuiteObject
argument.static TestSuite
create(String name)
Create and return a new test suite.TestCompletion
run()
Run the testsuite with the default options.TestCompletion
run(Vertx vertx)
Run the testsuite with the default options and the specifiedvertx
instance.TestCompletion
run(Vertx vertx, TestOptions options)
Run the testsuite with the specifiedoptions
and the specifiedvertx
instance.TestCompletion
run(TestOptions options)
Run the testsuite with the specifiedoptions
.TestSuite
test(String name, int repeat, Handler<TestContext> testCase)
Add a new test case to the suite.TestSuite
test(String name, Handler<TestContext> testCase)
Add a new test case to the suite.
-
-
-
Method Detail
-
create
static TestSuite create(String name)
Create and return a new test suite.- Parameters:
name
- the test suite name- Returns:
- the created test suite
-
create
static TestSuite create(Object testSuiteObject)
Create and return a new test suite configured after thetestSuiteObject
argument. ThetestSuiteObject
argument methods are inspected and the public, non static methods withTestContext
parameter are retained and mapped to a Vertx Unit test suite via the method name:before
:before(io.vertx.core.Handler<io.vertx.ext.unit.TestContext>)
callbackafter
:after(io.vertx.core.Handler<io.vertx.ext.unit.TestContext>)
callbackbeforeEach
:beforeEach(io.vertx.core.Handler<io.vertx.ext.unit.TestContext>)
callbackafterEach
:afterEach(io.vertx.core.Handler<io.vertx.ext.unit.TestContext>)
callback- when the name starts with
test
:test(java.lang.String, io.vertx.core.Handler<io.vertx.ext.unit.TestContext>)
callback named after the method name
- Parameters:
testSuiteObject
- the test suite object- Returns:
- the configured test suite
-
before
TestSuite before(Handler<TestContext> callback)
Set a callback executed before the tests.- Parameters:
callback
- the callback- Returns:
- a reference to this, so the API can be used fluently
-
beforeEach
TestSuite beforeEach(Handler<TestContext> callback)
Set a callback executed before each test and after the suitebefore
callback.- Parameters:
callback
- the callback- Returns:
- a reference to this, so the API can be used fluently
-
after
TestSuite after(Handler<TestContext> callback)
Set a callback executed after the tests.- Parameters:
callback
- the callback- Returns:
- a reference to this, so the API can be used fluently
-
afterEach
TestSuite afterEach(Handler<TestContext> callback)
Set a callback executed after each test and before the suiteafter
callback.- Parameters:
callback
- the callback- Returns:
- a reference to this, so the API can be used fluently
-
test
TestSuite test(String name, Handler<TestContext> testCase)
Add a new test case to the suite.- Parameters:
name
- the test case nametestCase
- the test case- Returns:
- a reference to this, so the API can be used fluently
-
test
TestSuite test(String name, int repeat, Handler<TestContext> testCase)
Add a new test case to the suite.- Parameters:
name
- the test case namerepeat
- the number of times the test should be repeatedtestCase
- the test case- Returns:
- a reference to this, so the API can be used fluently
-
run
TestCompletion run()
Run the testsuite with the default options. When the test suite is executed in a Vertx context (i.e `Vertx.currentContext()` returns a context) this context's event loop is used for running the test suite. Otherwise it is executed in the current thread. The returnedCompletion
object can be used to get a completion callback.- Returns:
- the related test completion
-
run
TestCompletion run(TestOptions options)
Run the testsuite with the specifiedoptions
. When the test suite is executed in a Vertx context (i.e `Vertx.currentContext()` returns a context) this context's event loop is used for running the test suite unless theTestOptions.setUseEventLoop(Boolean)
is set tofalse
. In this case it is executed by the current thread. Otherwise, the test suite will be executed in the current thread whenTestOptions.setUseEventLoop(Boolean)
is set tofalse
ornull
. If the value istrue
, this methods throws anIllegalStateException
. The returnedCompletion
object can be used to get a completion callback.- Parameters:
options
- the test options- Returns:
- the related test completion
-
run
TestCompletion run(Vertx vertx)
Run the testsuite with the default options and the specifiedvertx
instance. The test suite will be executed on the event loop provided by thevertx
argument. The returnedCompletion
object can be used to get a completion callback.- Parameters:
vertx
- the vertx instance- Returns:
- the related test completion
-
run
TestCompletion run(Vertx vertx, TestOptions options)
Run the testsuite with the specifiedoptions
and the specifiedvertx
instance. The test suite will be executed on the event loop provided by thevertx
argument whenTestOptions.setUseEventLoop(Boolean)
is not set tofalse
. The returnedCompletion
object can be used to get a completion callback.- Parameters:
vertx
- the vertx instanceoptions
- the test options- Returns:
- the related test completion
-
-