How to unit test a method whose side effect is to call other method?

后端 未结 3 1883
遥遥无期
遥遥无期 2021-01-26 17:54

Here is my example:

void doneWithCurrentState(State state) {
    switch (state) {
        case State.Normal:
            // this method is never actually called          


        
3条回答
  •  悲哀的现实
    2021-01-26 18:45

    If you wrote this not test-first, an obvious way to write it would be to write one case, then copy-paste into the next case. An easy mistake to make in that case would be to forget to update the parameter to updateViewState(). So (for instance) you might find yourself going from State.Focus to State.Normal. The test you've written, although it may seem weak to you, protects against mistakes of that nature. So I think it's doing what it should.

提交回复
热议问题