如何捕获 OCUnit 测试通过/失败消息/事件

发布于 2024-07-08 14:20:28 字数 389 浏览 10 评论 0原文

我正在尝试将 xcodebuild 和 OCUnit 与我的持续集成服务器 (TeamCity) 一起使用。

JetBrains 为 boost::test 和 CppUnit 提供测试观察器实现,以 TeamCity 可以解释的方式格式化测试输出。 如果我想使用 OCUnit,我需要做类似的事情。

OCUnit 中似乎有一个 SenTestObserver 类,但我不知道应该如何使用它,并且 OCUnit 主页 似乎没有提供任何有关此事的文档。

I'm trying to use xcodebuild and OCUnit with my Continuous Integration server (TeamCity).

JetBrains offers test observer implementations for boost::test and CppUnit that format test output in a way that TeamCity can interpret. I need to do something similar for OCUnit if I want to use it.

There appears to be a SenTestObserver class in OCUnit but I'm ignorant of how exactly it should be used, and the OCUnit homepage doesn't seem to provide any documentation on the matter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情深如许 2024-07-15 14:20:28

您可以通过扩展 SenTestObserver 类并实现通知侦听器来编写自己的观察者

  • (void) testSuiteDidStart:(NSNotification *) aNotification
  • (void) testSuiteDidStop:(NSNotification *) aNotification
  • (void) testCaseDidStart:(NSNotification *) aNotification
  • (void) testCaseDidStop :(NSNotification *) aNotification
  • (void) testCaseDidFail:(NSNotification *) aNotification

然后使用您的类名称将一个条目添加到 info.plist SenTestObserverClass 中。

至少在我熟悉的 OCUnit 版本中 SenTestObserver 是等量有用/等量损坏的。 我只是完全跳过它并在我自己的班级中自己注册通知。 (有关通知名称的定义,请参阅 SenTestSuiteRun.h 和 SenTestCaseRun.h)。

您可以使用通知的测试和运行属性来访问 SenTestSuite 和 SenTestSuiteRun 实例,并且运行实例包含实际结果所需的信息。

You can write your own observer by extending the SenTestObserver class and implementing the notification listeners

  • (void) testSuiteDidStart:(NSNotification *) aNotification
  • (void) testSuiteDidStop:(NSNotification *) aNotification
  • (void) testCaseDidStart:(NSNotification *) aNotification
  • (void) testCaseDidStop:(NSNotification *) aNotification
  • (void) testCaseDidFail:(NSNotification *) aNotification

then add an entry to the info.plist SenTestObserverClass with the name of your class.

At least in the version of OCUnit i'm familiar with SenTestObserver is equal parts useful/equal parts broken. I just skip it altogether and register for the notifications myself in my own class. (see SenTestSuiteRun.h and SenTestCaseRun.h for the defines of the notification names).

You can use the test and run properties of the notification to access the SenTestSuite and SenTestSuiteRun instances, and the run instance contains the info needed on the actual results.

打小就很酷 2024-07-15 14:20:28

我实现了一个简单的 Teamcity 适配器,您可以在此处查看要点。 SenTestObserver 并没有完全损坏,它只是没有遵循最佳实践:

这是您需要在 Observer 子类中调用以正确注册它的内容:

+(void)initialize
{
    [[NSUserDefaults standardUserDefaults] setValue:@"TeamCityAdapter" forKey:@"SenTestObserverClass"];
    // we need to force SenTestObserver to register us as a handler
    // SenTestObserver is properly guarding against this invocation so nothing bad will hapen
    // but this is required (bad design on SenTestObserver's side)...
    [super initialize];
}

因为 SenTestObserver 的初始化如下所示:

+ (void) initialize
{
    if ([self class] == [SenTestObserver class]) {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSDictionary *registeredDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
            @"SenTestLog" , @"SenTestObserverClass",
            nil];
        [defaults registerDefaults:registeredDefaults];
        [NSClassFromString ([defaults objectForKey:@"SenTestObserverClass"]) class]; // make sure default observer is loaded
    }

    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"SenTestObserverClass"] isEqualToString:NSStringFromClass(self)]) {
        [self setCurrentObserver:self];
    }
}

我希望这会帮助其他人正在寻找 OCUnit / SenTestingKit 的 teamcity 适配器。

I have implemented a simple Teamcity Adapter, you can view the gist here. SenTestObserver isn't exactly broken, it simply doesn't adhere to the best practices:

This is what you need to call in your Observer subclass to have it properly registered:

+(void)initialize
{
    [[NSUserDefaults standardUserDefaults] setValue:@"TeamCityAdapter" forKey:@"SenTestObserverClass"];
    // we need to force SenTestObserver to register us as a handler
    // SenTestObserver is properly guarding against this invocation so nothing bad will hapen
    // but this is required (bad design on SenTestObserver's side)...
    [super initialize];
}

because SenTestObserver's initialize looks like this:

+ (void) initialize
{
    if ([self class] == [SenTestObserver class]) {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSDictionary *registeredDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
            @"SenTestLog" , @"SenTestObserverClass",
            nil];
        [defaults registerDefaults:registeredDefaults];
        [NSClassFromString ([defaults objectForKey:@"SenTestObserverClass"]) class]; // make sure default observer is loaded
    }

    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"SenTestObserverClass"] isEqualToString:NSStringFromClass(self)]) {
        [self setCurrentObserver:self];
    }
}

I hope this will help others out there looking for a teamcity adapter for OCUnit / SenTestingKit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文