public final class Cuppa
extends java.lang.Object
Annotate your class with Test
.
public class ListTest {
{
describe("List", () -> {
describe("#indexOf", () -> {
it("returns -1 when the value is not present", () -> {
List<Integer> list = Arrays.asList(1, 2, 3);
assertThat(list.indexOf(5)).isEqualTo(-1);
});
});
});
}
}
Modifier and Type | Method and Description |
---|---|
static void |
after(HookFunction function)
Registers the given function to be executed once, after all tests in the current and nested blocks.
|
static void |
after(java.lang.String description,
HookFunction function)
Registers the given function to be executed once, after all tests in the current block.
|
static void |
afterEach(HookFunction function)
Registers the given function to be executed after each test in the current and nested blocks.
|
static void |
afterEach(java.lang.String description,
HookFunction function)
Registers the given function to be executed after each test in the current and nested blocks.
|
static void |
before(HookFunction function)
Registers the given function to be executed once, before any tests in the current and nested blocks.
|
static void |
before(java.lang.String description,
HookFunction function)
Registers the given function to be executed once, before any tests in the current and nested blocks.
|
static void |
beforeEach(HookFunction function)
Registers the given function to be executed before each test in the current and nested blocks.
|
static void |
beforeEach(java.lang.String description,
HookFunction function)
Registers the given function to be executed before each test in the current and nested blocks.
|
static void |
describe(java.lang.String description,
TestBlockFunction function)
Registers a 'describe' block of tests.
|
static void |
it(java.lang.String description)
Registers a pending test.
|
static void |
it(java.lang.String description,
TestFunction function)
Registers a test function to be run.
|
static TestBuilder |
only()
Mark a test or block of tests as the only tests that should be run.
|
static TestBuilder |
skip()
Mark a test or block of tests to be skipped.
|
static Option |
tags(java.lang.String... tags)
Decorates tests with a set of tags.
|
static void |
when(java.lang.String description,
TestBlockFunction function)
Registers a 'when' block of tests.
|
static TestBuilder |
with(Option<?>... options)
Decorate a test or block of tests with additional options.
|
public static void describe(java.lang.String description, TestBlockFunction function)
Use 'describe' blocks to group together tests that describe the same thing. Blocks may be nested within other blocks.
description
- The description of the 'describe' block. Used solely for reporting.function
- A function that will define tests and/or test blocks. This function will be executed immediately.public static void when(java.lang.String description, TestBlockFunction function)
Use 'when' blocks to group together tests that share some context. Blocks may be nested within other blocks.
description
- The description of the 'when' block. Used solely for reporting.function
- A function that will define tests and/or test blocks. This function will be executed immediately.public static void before(HookFunction function)
function
- The 'before' block.public static void before(java.lang.String description, HookFunction function)
description
- A description of the function. Displayed when the function throws an exception.function
- The function to execute.public static void after(HookFunction function)
function
- The function to execute.public static void after(java.lang.String description, HookFunction function)
description
- A description of the function. Displayed when the function throws an exception.function
- The function to execute.public static void beforeEach(HookFunction function)
function
- The function to execute.public static void beforeEach(java.lang.String description, HookFunction function)
description
- A description of the function. Displayed when the function throws an exception.function
- The function to execute.public static void afterEach(HookFunction function)
function
- The function to execute.public static void afterEach(java.lang.String description, HookFunction function)
description
- A description of the function. Displayed when the function throws an exception.function
- The function to execute.public static void it(java.lang.String description, TestFunction function)
description
- A description of the behaviour that the function will assert.function
- The function to execute.public static void it(java.lang.String description)
A pending test has no implementation and acts as a reminder to the developer to write the implementation later.
description
- A description of the behaviour that this test will assert.public static TestBuilder with(Option<?>... options)
tags(String...)
.
Multiple options can be either passed as additional arguments or chained using the returned builder.
with(tags("slow")).
it("takes a long time to start", () -> {
// ...
});
options
- Options to apply to the test/block.tags(String...)
public static TestBuilder skip()
The test(s) may still be included in test reports, but marked as skipped.
skip().it("does something", () -> {
// Will not be run.
});
public static TestBuilder only()
If at least one test is marked as only
then all tests not marked as only
will not be run.
only().it("does something", () -> {
// ...
});
public static Option tags(java.lang.String... tags)
Apply to a test or block of tests by passing the result of this method to
with(Option...)
.
with(tags("slow")).
it("takes a long time to start", () -> {
// ...
});
tags
- String identifiers that can be used when running Cuppa to include or exclude a test/block.with(Option...)
.with(Option...)