Class BTest
java.lang.Object
org.blocktest.BTest
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionFor a given lambda test, provide a list of values as the arguments to the lambda function.static BTestDeclares a block test.static BTestDeclares a block test with a name.Check that the actual object is equal to the expected object.Check that the actual object is equal to the expected object within a delta.checkFalse(Object value) Check that the given value or expression is false.Check the flow of the block under test, as a sequence of Flow objects.checkReturnEq(Object expected) Checks that the return value of the block under test is equal to the expected value.checkReturnEq(Object expected, Object delta) Checks that the return value of the block under test is equal to the expected value within a delta.Check that the return value of the block or lambda is false.Check that the return value of the block or lambda is true.Check that the given value or expression is true.delay(long time) TODO: Need a real example, not sure what this does.end()TODO: What is the purpose of this?Deprecated, use end(EndAt value) instead.Deprecated, use end(EndAt value, boolean endAfter) instead.Set the stoppoint of the block test to be at the value specified by the EndAt enum.Set the stoppoint of the block test to be at the value specified by the EndAt enum, and decide whether to include the construct specified by the EndAt enum.Set the stoppoint of the block test to be at the value specified by the EndAt enum, and at the specified instance.Set the stoppoint of the block test to be at the value specified by the EndAt enum, and at the specified instance, and decide whether to include the construct specified by the EndAt enum.Check that the block or lambda under test throws an exception.Assigns a value to a variable that is used in the block under test.Assigns a value to a variable that is used in the block under test, with a specified type.static booleangroup()TODO: Never seen this used.static BTestDeclares a lambda test.static BTestlambdatest(String name) Declares a lambda test with a name.Mock the method calls of the block or lambda under test.TODO: What does this do?Specifies that for the given list of variables, do not initialize their values by inferring from context.Set up the right environment to test a block or lambda by executing the Runnable.Deprecated, use start(EndAt value) instead.Deprecated, use start(EndAt value, boolean endAfter) instead.Set the start point of the block test to be at the value specified by the EndAt enum.Set the start point of the block test to be at the value specified by the EndAt enum, and decide whether to include the construct specified by the EndAt enum.Set the start point of the block test to be at the value specified by the EndAt enum, and at the specified instance.Set the start point of the block test to be at the value specified by the EndAt enum, and at the specified instance, and decide whether to include the construct specified by the EndAt enum.
-
Field Details
-
btest
-
-
Method Details
-
blocktest
Declares a block test. It should be followed by assignment and assertions.- Returns:
- a BTest object to chain assignment, assertions, and stoppoints.
-
lambdatest
Declares a lambda test. It should be followed by assignment and assertions.- Returns:
- a BTest object to chain assignment, assertions, and stoppoints.
-
blocktest
-
lambdatest
-
checkEq
Check that the actual object is equal to the expected object. e.g.checkEq(lastChunkSize, 1048576)Sometimes the actual object is a variable that is not yet declared in the original code, one can use a String variable representing its name to refer to it. e.g.checkEq("lastChunkSize", 1048576)- Parameters:
actual- the actual object, or a String representing the name of the actual object.expected- the expected object.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
checkEq
Check that the actual object is equal to the expected object within a delta. e.g.checkEq(A[4][1], -136, 1)- Parameters:
actual- the actual object, or a String representing the name of the actual object.expected- the expected object.delta- the delta within which the actual and expected objects should be equal.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
checkReturnEq
-
checkReturnEq
Checks that the return value of the block under test is equal to the expected value within a delta. e.g.checkReturnEq(-2, 0.5)- Parameters:
expected- the expected return value.delta- the delta within which the return value should be equal to the expected value.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
given
Assigns a value to a variable that is used in the block under test. e.g.given(bufferSize, 4096)- Parameters:
variable- the variable to assign the value to.value- the value to assign to the variable.- Returns:
- a BTest object to chain additional assignments, assertions, and stoppoints.
-
noInit
Specifies that for the given list of variables, do not initialize their values by inferring from context. e.g.noInit(lineReader, context)- Parameters:
variables- a list of variables that should not be initialized.- Returns:
- a BTest object to chain additional assignments, assertions, and stoppoints.
-
args
-
given
Assigns a value to a variable that is used in the block under test, with a specified type. This is because sometimes the type cannot be easily inferred. Usually used for lambda tests. e.g.given("config", Configuration.getDefault(), "Configuration")- Parameters:
variable- the variable to assign the value to.value- the value to assign to the variable.type- the type of the variable, currently using Strings to represent types.- Returns:
- a BTest object to chain additional assignments, assertions, and stoppoints.
-
setup
-
setup
Set up the right environment to test a block or lambda by executing the Runnable. e.g.setup(() -> { setupOnce(); setupTwice(); })- Parameters:
setupFunction- a Runnable object that contains necessary setups for the block or lambda under test.- Returns:
- a BTest object to chain additional assignments, assertions, and stoppoints.
-
checkTrue
-
checkFalse
-
checkReturnTrue
Check that the return value of the block or lambda is true. e.g.blocktest().checkReturnTrue()TODO: Never seen a real usage of this case.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
checkReturnFalse
Check that the return value of the block or lambda is false. e.g.blocktest().checkReturnFalse()TODO: Never seen a real usage of this case.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
checkFlow
Check the flow of the block under test, as a sequence of Flow objects. For instance, for this example:// Block test location if (first) { if (second) { // do something A } else { // do something B } } else { // do something C }One can write a block test like this:blocktest().given(first, true).given(second, false).checkFlow(IfStmt().Then().IfStmt().Else())to check that the flow of the block under test is: 1) Check the first condition; 2) Execute the then branch of the first if statement; 3) Check the second condition; 4) Execute the else branch of the second if statement;- Parameters:
value- a sequence of Flow objects representing the expected flow.- Returns:
- aBTest object to chain additional assertions and stoppoints.
-
expect
-
end
TODO: What is the purpose of this? Ending the btest at a default location? -
end
-
end
Set the stoppoint of the block test to be at the value specified by the EndAt enum. Block tests using .end(..) should be declared right before the block or lambda under test. e.g.blocktest()....end(FIRST_ASSIGN)- Parameters:
value- the end point of the block test.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
end
Set the stoppoint of the block test to be at the value specified by the EndAt enum, and at the specified instance. e.g.blocktest()....end(FIRST_ASSIGN, 2)means that the block test should stop at the second assignment.- Parameters:
value- the end point of the block test.at- the instance of the end point.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
end
-
end
Set the stoppoint of the block test to be at the value specified by the EndAt enum, and decide whether to include the construct specified by the EndAt enum. e.g.blocktest()....end(FIRST_BLOCK, true)means that the block test should stop after the first block. Otherwise, it will stop right before the first block that follows.- Parameters:
value- the end point of the block test.endAfter- whether to include the construct specified by the EndAt enum.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
end
Set the stoppoint of the block test to be at the value specified by the EndAt enum, and at the specified instance, and decide whether to include the construct specified by the EndAt enum. e.g.blocktest()....end(FIRST_BLOCK, 2, true)means that the block test should stop after the second block.- Parameters:
value- the end point of the block test.at- the instance of the end point.endAfter- whether to include the construct specified by the EndAt enum.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
start
-
start
-
start
Set the start point of the block test to be at the value specified by the EndAt enum, and at the specified instance. e.g.blocktest()....start(FIRST_ASSIGN, 2)means that the block test should start at the second assignment.- Parameters:
value- the start point of the block test.at- the instance of the start point.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
start
-
start
Set the start point of the block test to be at the value specified by the EndAt enum, and decide whether to include the construct specified by the EndAt enum. e.g.blocktest()....start(FIRST_BLOCK, true)means that the block test should start after the first block.- Parameters:
value- the start point of the block test.endAfter- whether to include the construct specified by the EndAt enum.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
start
Set the start point of the block test to be at the value specified by the EndAt enum, and at the specified instance, and decide whether to include the construct specified by the EndAt enum. e.g.blocktest()....start(FIRST_BLOCK, 2, true)means that the block test should start after the second block.- Parameters:
value- the start point of the block test.at- the instance of the start point.endAfter- whether to include the construct specified by the EndAt enum.- Returns:
- a BTest object to chain additional assertions and stoppoints.
-
mock
Mock the method calls of the block or lambda under test. This is similar to the given clause, but for method calls. e.g.blocktest().given(a, 1).mock("someCall(p)", 1).checkReturnTrue();- Parameters:
value- the method calls to mock.- Returns:
- a BTest object to chain additional assignments, assertions, and stoppoints.
-
mockStr
-
delay
TODO: Need a real example, not sure what this does. -
group
public static boolean group()TODO: Never seen this used. And what does group() mean for block tests, where there might be multiple conditions in different places?
-