public abstract class FreeSpecBase extends Object implements LambdaTest
Common base class containing framework agnostic implementation of FreeSpec-like classes.
Modifier and Type | Class and Description |
---|---|
static interface |
FreeSpecBase.F0WithException<R> |
Constructor and Description |
---|
FreeSpecBase() |
Modifier and Type | Method and Description |
---|---|
Optional<Section> |
getCurrentSection() |
static Reporter |
getDefaultReporter() |
boolean |
getExpectFailFast() |
Reporter |
getReporter()
Gets the currently used reporter.
|
boolean |
getRunInParallel() |
String |
getSuiteName() |
List<DefaultTestCase> |
getTestCases() |
<T extends Throwable> |
intercept(Class<T> exceptionType,
RunnableWithException throwing)
Intercept exceptions of type <code>exceptionType</code> and fail if no
such exception or an exception with an incompatible type was thrown.
|
<T extends Throwable> |
intercept(Class<T> exceptionType,
String messageRegex,
RunnableWithException throwing)
Intercept exceptions of type <code>exceptionType</code> and fail if no
such exception or an exception with an incompatible type was thrown or it
the message does not match a given pattern.
|
void |
pending()
Marks the test as pending.
|
void |
section(String section,
Runnable code) |
static void |
setDefaultReporter(Reporter reporter)
Set the default reporter.
|
void |
setExpectFailFast(boolean failFast)
If
true , the first failed assertion will also fail the test. |
void |
setReporter(Reporter reporter)
Set the
Reporter to be used. |
void |
setRunInParallel(boolean runInParallel)
If
true tests in this suite can be run in parallel. |
void |
test(String name,
RunnableWithException testCase)
Adds a test to the test suite.
|
static <T> T |
withDefaultReporter(Reporter reporter,
FreeSpecBase.F0WithException<T> f)
Executes a given function
f with the default reporter set to
reporter , and restored the previous default reporter afterwards. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
pending
public static Reporter getDefaultReporter()
public static void setDefaultReporter(Reporter reporter)
Set the default reporter.
public static <T> T withDefaultReporter(Reporter reporter, FreeSpecBase.F0WithException<T> f) throws Exception
Executes a given function f
with the default reporter set to
reporter
, and restored the previous default reporter afterwards.
reporter
- The default reporter to be used while executing f
.f
- The function to apply.f
.Exception
- All expeceptions thrown by f
.public boolean getRunInParallel()
public void setRunInParallel(boolean runInParallel)
LambdaTest
If true
tests in this suite can be run in parallel.
setRunInParallel
in interface LambdaTest
runInParallel
- If true
, tests may execute in parallel.public boolean getExpectFailFast()
public void setExpectFailFast(boolean failFast)
LambdaTest
If true
, the first failed assertion will also fail the test. If
false
, the test runs as long as possible, potentially collection
multipe failed assertions.
setExpectFailFast
in interface LambdaTest
failFast
- If true
, to fail fast.public String getSuiteName()
public Reporter getReporter()
LambdaTest
Gets the currently used reporter.
getReporter
in interface LambdaTest
public void setReporter(Reporter reporter)
LambdaTest
Set the Reporter
to be used.
setReporter
in interface LambdaTest
reporter
- The Reporter
to be used.public void test(String name, RunnableWithException testCase)
Adds a test to the test suite.
name
- The name of the new test.testCase
- The test case. It should return when it is successful, else it
should throw an exception. Depending on the underlying test
framework/runner, there are different exceptions types, which
are recognized and handled. See in the concrete implementation
documentation for more details.public List<DefaultTestCase> getTestCases()
public <T extends Throwable> T intercept(Class<T> exceptionType, RunnableWithException throwing) throws Exception
Intercept exceptions of type <code>exceptionType</code> and fail if no such exception or an exception with an incompatible type was thrown.
intercept
in interface LambdaTest
exceptionType
- The exception type to intercept.throwing
- The execution block which is expected to throw the exception.Exception
- If no exception was thrown or an exception with an
incompatible type was thrown.public <T extends Throwable> T intercept(Class<T> exceptionType, String messageRegex, RunnableWithException throwing) throws Exception
Intercept exceptions of type <code>exceptionType</code> and fail if no such exception or an exception with an incompatible type was thrown or it the message does not match a given pattern.
intercept
in interface LambdaTest
exceptionType
- The exception type to intercept.messageRegex
- A regular expression pattern to match the expected message.
See Pattern
for details.throwing
- The execution block which is expected to throw the exception.Exception
- If no exception was thrown or an exception with an
incompatible type was thrown or if the message of the
exception did not match the expected pattern.public void pending()
LambdaTest
Marks the test as pending. Instructions after pending()
will not be
executed.
pending
in interface LambdaTest
Copyright © 2019. All rights reserved.