Как может я модульный тест объект, внутренний к методу в Objective C?

Если вы заглянете в «Консоль» при попытке использовать инструменты командной строки, вы обнаружите, что на самом деле существует «неофициальная» ссылка на инструменты командной строки Mountain Lion!

Так что просто try:

http://adcdownload.apple.com/ios/ios_simulator__resigned/cltools_mountainliondp2_march12.dmg

Вот мой журнал консоли:

01/04/2012 15:41:54.258 Xcode: [MT] DVTDownloadable: Download failed. Downloadable: {
    dependencies =     (
    );
    fileSize = 141452226;
    identifier = "Xcode.CLTools.10.8";
    name = "Command Line Tools";
    source = "http://adcdownload.apple.com/ios/ios_simulator__resigned/cltools_mountainliondp2_march12.dmg";
    userInfo =     {
        ActivationPredicate = "$MAC_OS_X_VERSION >= '10.8.0' && $MAC_OS_X_VERSION < '10.9.0'";
        InstallPrefix = "/";
        InstalledIfAllSHA1SumsMatch =         {
            "/usr/bin/clang" = 600c35175775a6002452a88f17e00c570cd2e2d0;
        };
        Summary = "Before installing, note that from within Terminal you can use the XCRUN tool to launch compilers and other tools embedded within the Xcode application. Use the XCODE-SELECT tool to define which version of Xcode is active.  Type \"man xcrun\" from within Terminal to find out more.\n\nDownloading this package will install copies of the core command line tools and system headers into system folders, including the LLVM compiler, linker, and build tools.";
        "Xcode.SDKs" =         (
        );
    };
    version = "1.1.1";
}. Error: Error Domain=NSCocoaErrorDomain Code=3840 "The data couldn’t be read because it has been corrupted." (Encountered unknown ampersand-escape sequence at line 18) UserInfo=0x401bc8e60 {NSDebugDescription=Encountered unknown ampersand-escape sequence at line 18, kCFPropertyListOldStyleParsingError=The data couldn’t be read because it has been corrupted.}

6
задан Kevlar 6 July 2009 в 20:56
поделиться

3 ответа

Вы можете использовать OCMock, но вам придется изменить код, чтобы либо использовать объект Destination , либо использовать одноэлементный объект, который вы могли бы сначала заменить своим фиктивным объектом.

Самый чистый способ сделать это, вероятно, заключался бы в реализации метода

-(void) navigate:(NavContext *)context destination:(Destination *)dest;

. Измените реализацию - (void) navigate: (NavContext *) context на следующее:

- (void) navigate:(NavContext *)context {
    Destination * dest = [[Destination alloc] initWithContext:context];
    [self navigate:context destination:dest];
    [dest release];
}

Это позволит вашим тестам напрямую вызывать метод с дополнительным параметром. (На других языках вы могли бы реализовать это, просто указав значение по умолчанию для параметра назначения, но Objective-C не поддерживает параметры по умолчанию.)

5
ответ дан 17 December 2019 в 02:32
поделиться

What i want to verify is that if context.isValid is true, that doSomething is called on dest

I think you may be testing the wrong thing here. You can safely assume (I hope) that boolean statements work correctly in ObjC. Wouldn't you want to test the Context object instead? If context.isValid then you're guaranteed that the [dest doSomething] branch gets executed.

1
ответ дан 17 December 2019 в 02:32
поделиться

Это вполне возможно с использованием таких интересных приемов, как swizzling , но, вероятно, все идет не так путь. Если здесь'

0
ответ дан 17 December 2019 в 02:32
поделиться
Другие вопросы по тегам:

Похожие вопросы: