Reputation: 67223
Is it possible to unit test a method like the following?
void AddNumbers() {
int i = 2+2;
}
In other words, a method with no side effects really. Or are methods like these skipped and not usually tested? I would assume that i
would normally be made a class-level variable, but then this has its drawbacks (nothing very big though).
Upvotes: 1
Views: 331
Reputation: 29021
Mmm... this method has no side effect, but it is effectively doing nothing. A method without side effects, IMO, would be one that returns a value without changing any state (class or application), and this is how it can be tested again expected results. For any implementation, the method you wrote is invisible.
Upvotes: 1
Reputation: 40336
There is no value to a method with neither side-effects nor primary effects, such as you've presented. Calling it - from test code or production code - would, well, have no effect. So there's nothing to test, and no reason for the method.
Upvotes: 6