How do I trap OCUnit test pass/failure messages/events

前端 未结 2 848
Happy的楠姐
Happy的楠姐 2021-02-06 01:17

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

JetBrains offers test observer implementations for boost::test and CppUnit t

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 02:00

    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.

提交回复
热议问题