Xcode 4.2,无法运行单元测试 [英] Xcode 4.2, can't run unit test

查看:23
本文介绍了Xcode 4.2,无法运行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的 Xcode 4.2 Cocoa 项目,一个可可库.默认情况下,单元测试带有以下单元测试:

I have created a new Xcode 4.2 Cocoa project, a cocoa library. By default, the unit tests come with the following unit test:

- (void)testExample
{
    STFail(@"Unit tests are not implemented yet in learning01Tests");
}

如果我按 ⌘U,我可以看到测试构建并按预期失败.现在,我添加以下新行以测试我创建的外部类:

If I press ⌘U I can see the test building and failing as expected. Now, I add the new following lines in order to test an external class I have created:

#import "svc01.h"

- (void)testMyClass
{
    svc01* svc = [[svc01 alloc]init];
    int expected = [svc addTwoNumbers:10 :10];
    STAssertTrue(21 == expected, @"It should fail!");
}

我可以看到两个测试(默认和我的方法)都按预期失败.问题是有时,即使我按下命令测试,它也会弹出消息构建成功"然后测试成功",但如果我查看输出控制台,它会显示测试运行 0"

I can see both tests (the default and my method) failing as expected. The issue is that sometimes, even if I press the command Test, it popups the message "Build succeed" and then "Test succeed" but if I look at the output console it says "tests run 0"

我做错了什么吗?

更新

现在我已经更改了我的测试方法的签名,但它不再起作用了.我有这个:

Right now I have changed the signature of my test methods and it does not work anymore. I have this:

#import <SenTestingKit/SenTestingKit.h>

@interface learning01Tests : SenTestCase
- (void)sumTwoIntegerShouldPass;
- (void)sumTwoZeroShouldThrow;

@end
- (void)sumTwoIntegerShouldPass
{
    svc01* svc = [[svc01 alloc]init];
    int expected = [svc addTwoNumbers:10 :10];
    STAssertTrue(20 == expected, @"It should fail!");
}

- (void)sumTwoZeroShouldThrow
{
    svc01* svc = [[svc01 alloc]init];
    int expected = [svc addTwoNumbers:0 :0];
    STAssertTrue(21 == expected, @"It should fail!");
}

这是 Xcode 输出:

And this is the Xcode output:

-bfxnldmmxzsspnbglmrpwsnweqkd/Build/Products/Debug/learning01Tests.octest(Tests)' started at 2011-12-26 14:45:26 +0000
Test Suite 'learning01Tests' started at 2011-12-26 14:45:26 +0000
Test Suite 'learning01Tests' finished at 2011-12-26 14:45:26 +0000.
Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds
Test Suite '/Users/raffaeu/Library/Developer/Xcode/DerivedData/learning01-bfxnldmmxzsspnbglmrpwsnweqkd/Build/Products/Debug/learning01Tests.octest(Tests)' finished at 2011-12-26 14:45:26 +0000.
Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.002) seconds

推荐答案

在 Xcode 4.2 中,您需要使用前缀 test 标记您的测试方法,以便让它们运行.我在这里找到了解决方案:http://www.blog.holsee.com/2011/07/tests-driven-groking-of-cocoa-objective-c/

In Xcode 4.2 you need to mark your test method with the prefix test in order to get them running. I found the solution here: http://www.blog.holsee.com/2011/07/tests-driven-groking-of-cocoa-objective-c/

这会起作用:

- (void)testThatsumTwoZeroShouldThrow
{
    svc01* svc = [[svc01 alloc]init];
    int expected = [svc addTwoNumbers:0 :0];
    STAssertTrue(21 == expected, @"It should fail!");
}

虽然这不会:

- (void)TestThatsumTwoZeroShouldThrow
{
    svc01* svc = [[svc01 alloc]init];
    int expected = [svc addTwoNumbers:0 :0];
    STAssertTrue(21 == expected, @"It should fail!");
}

这篇关于Xcode 4.2,无法运行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆