I want to modify the behavior of some function without being the author of that function. What I control is that I can ask the author to follow some pattern, e.g. use a base class, use a certain decorator, property etc.
If in python, I would use a decorator to change the behavior of a method.
As an example, My goal: Improve code coverage by automatically testing over multiple input data.
Pseudo code:
@implementation SomeTestSuiteClass
// If in python, I would add a decorator here to change the behavior of the following method
-(void)testSample1 {
input = SpecialProvider();
output = FeatureToTest(input);
SpecialAssert(output);
}
@end
What I want: During test, the testSample1
method will be called multiple times. Each time, the SpecialProvider
will emit a different input data. Same for the SpecialAssert
, which can verify the output corresponding to the given input.
SpecialProvider
and SpecialAssert
will be API under my control/ownership (i.e. I write them).
The SomeTestSuiteClass
together with the testSample1
will be written by the user (i.e. test writer).
Is there a way for Objective-C to achieve "what I want" above?