Test if another method was called

前端 未结 4 1497
生来不讨喜
生来不讨喜 2021-01-04 18:33

So I\'m sure there is something like this out there but I have been searching for an hour and haven\'t found exactly what I am looking for. say I have a class that looks lik

4条回答
  •  迷失自我
    2021-01-04 19:04

    I think you want to look at Mock objects. You can create a mock of MyClass, then set expectations that otherMethod() is called when you call myMethod and fails if it was not called.

    Here is a pretty good overview of them for java - http://www.scalatest.org/user_guide/testing_with_mock_objects

    One other major benefit of using Mocks, you can avoid side affects, like logging to NSLog or hitting a web server or printing) in your test.

提交回复
热议问题