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

前端 未结 2 843
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 01:49

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题