I have this method:
public bool CanExecute()
And after 70 commits, I added an extra parameter
public bool CanExecute(IStation target)
Now the problem is I have 7 unit tests covering this CanExecute methods testing various nulls/property combinations.
Adding this simple parameter required a fix of those 7 unit tests. The fix is simple but...
Is there a best practice and/or pattern to avoid this kind of hand-refactor required to update unit tests?
Suppose I know an extra parameter might be added in the near future, how'd I code the unit test to account for that? Is it just overkill or is there an idiom/pattern/something to follow?
EDIT: I could not simply add an overload because the IStation dependency is not optional. I was fixing a bug where an IStation instance was expected but none was available so it must be supplied via CanExecute... you see.
Refactoring tools seem to be the way to go. Thanks!
Could you not keep both methods in the code? Unless it is mandatory for the IStation parameter to be non null then you could get away with it without changing any existing code.
Alternatively if the parameter has a sensible default (again, like null!), resharper can take care of changes like this very easily. To add a new parameter, right click the function name and select Change signature... From here you can add new parameters with sensible defaults. RS will update all the calls so you don't have to !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With