Conditional Assertion - based on arguments
|Top Previous Next|
Isolator++ Professional allows you to assert that a method was called with specific arguments.
To do this use the Conditional Checkers in the ASSERT_WAS_CALLED statement. This works with ASSERT_NOT_CALLED and TIMES_CALLED
Note: only public methods are supported, use Custom Assertions with Predicates for private methods.
The conditional API is the same as Conditional Behavior Faking
Note: conditional asserts only works with value types, as Isolator++ Professional doesn't copy or save other types of argument for this check. Use Custom Assertions for this
Assuming the following class is in the production code
The following code with pass if the method was called with the specific arguments - the first is 1 and the second smaller than 2
Example with private methods with out/by-ref value-type arguments
Note: You can use BY_REF macro in conditions, instead of passing the pointer itself:
Using the same example as above, assuming GetAverageChildAge is private:
And for methods with out/by-ref value-type arguments you can use same construction:
Creating Custom Conditions
To create custom conditions, use the IS macro and implement the condition within the lambda method.
Using the previous code, Let's create a test that will pass only if the method was called with the child1 of 2 or 5. child2 can be any value (_)
Creating Custom Conditions between many arguments
To create a condition that requires testing multiple complex or inter-arguments testing use the predicate as show in Custom Assertions with Predicates
Copyright Typemock Ltd. 2009-2022. All Rights Reserved.