簡體   English   中英

xcode中的單元測試(使用GHUnit和OCMock)

[英]Unit Testing in xcode(Using GHUnit and OCMock)

在xcode中,我正在嘗試使用GHUnit和OCMock進行單元測試,如下所示:

單元測試Xcode

並按如下所述設置方法:

GHUnitTestCase

但是這種方法出現了錯誤

  • (void)setUpClass {}

當我如下初始化我的ViewController對象時:

#import <GHUnitIOS/GHUnit.h>
#import <OCMock/OCMock.h>
#import "RS_LoginRSViewController.h"

@interface SampleLibTest : GHTestCase
{
  RS_LoginRSViewController * login;
}
@end

@implementation SampleLibTest

// Run before each test method
- (void)setUp { }

// Run after each test method
- (void)tearDown { }

// Run before the tests are run for this class
- (void)setUpClass
{
 GHTestLog(@"Log with a test with the GHTestLog(...) for test specific logging.");
 login = [[RS_LoginRSViewController alloc]init];
}

// Run before the tests are run for this class
 - (void)tearDownClass { }

// Tests are prefixed by 'test' and contain no arguments and no return value
 - (void)testA {
 GHTestLog(@"Log with a test with the GHTestLog(...) for test specific logging.");
 }

 // Override any exceptions; By default exceptions are raised, causing a test failure
  - (void)failWithException:(NSException *)exception { }
 @end

但是由於Apple Mach-O Linker Error而出現錯誤:

架構i386的未定義符號:“ _ OBJC_CLASS _ $ _ RS_LoginRSViewController”,引用自:SampleTestCase.o中的objc-class-ref ld:找不到架構i386的符號clang:錯誤:鏈接器命令失敗,退出代碼為1(使用-v查看調用)

但是當我刪除線

     login = [[RS_LoginRSViewController alloc]init];

- (void)setUpClass

然后方法成功運行。為什么出現此錯誤? 任何幫助將不勝感激。

我通過添加必要的文件,框架和庫來構建測試目標項目的各個階段,從而解決了錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM