代码之家  ›  专栏  ›  技术社区  ›  gurghet

我应该测试一个经常与服务器同步的模型类吗?

  •  0
  • gurghet  · 技术社区  · 15 年前

    我该怎么做呢,因为显然有很多异步方法,而且在单元测试中无法(我知道)检查它们。

    例如:

    
    - (void) testSomeTest {
    // things
    [[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(helperTestSomeTest:)
    name:connectionFinished
    object:nil];
    // connect to server
    }
    - (void) helperTestSomeTest:(NSNotification)notification {
     STAssertWhatever(whathever, nil); // not working
    }
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Mike    15 年前

    您有各种各样的解决方案来进行单元测试。 Mock objects , Stubs 所有的假货都浮现在脑海中。

    它们看起来很相似,但是 this is a great look at the differences .

    顺便说一下,直接回答你的问题:是的,测试100%的代码。 一切 .