【问题标题】:Unit Testing in xcode(Using GHUnit and OCMock)xcode 中的单元测试(使用 GHUnit 和 OCMock)
【发布时间】:2013-08-13 12:24:44
【问题描述】:

在 xcode 中,我正在尝试使用 GHUnit 和 OCMock 进行单元测试,如下所述:

Unit Testing 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

方法然后它运行成功。为什么我收到这个错误? 任何帮助将不胜感激。

【问题讨论】:

  • 该错误表明 RS_LoginRSViewController 没有/尚未为模拟器编译。您的测试是否在设备上成功运行?
  • @Ben Flynn:我通过添加框架和库来构建阶段解决了错误..

标签: xcode unit-testing installation ocmock gh-unit


【解决方案1】:

我通过添加必要的文件、框架和库来解决错误,以构建项目测试目标的阶段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多