As part of some testing, I am temporarily replacing the contents of the message with those that will return a predictable set of test values. What is the standard Smalltalk-y way to do this kind of work? Is there any sample code to view?
Some explanations:
- No, this is not just a unit test. I am testing a large, complex system.
- Replacing the entire object at runtime is impractical. A significant accumulated state would have to be curtailed by testing without replacing the method.
- Subclass and replacement of one method are not generalized. I test dozens of similar classes and thousands of objects. Filling the class hierarchy with tiny one class of methods, one for each test case, will really suck - and this will require more updating if I change my test case.
Here is some pseudo code for what I want to write:
replaceMessage: 'fibonacci'
onClass: 'funFunctions'
with: 'returnsPredictableNumbersWithoutCalculatingThem'.
self runTestSet1.
restoreMessage: 'fibonacci'
onClass: 'funFunctions'.
self runFollowUpSet1. "Depends on state set by Set1"
replaceMessage: 'fibonacci'
onClass: 'funFunctions'
with: 'returnsPredictableNumbersWithoutCalculatingThemPart2'.
self runFollowUpSet2. "Depends on state set by followupset1"
restoreMessage: 'fibonacci'
onClass: 'funFunctions'.
source
share