Unit test results

Sometimes (according to Google – never ) one have a need to gather all results from unit tests. In example – to send them through the network. Why? Imagine that you...

Sometimes (according to Google – never :P ) one have a need to gather all results from unit tests. In example – to send them through the network. Why? Imagine that you need to report every unit test results to corporate server. Just to check for regressions… or something. I need it so my students can check “The Board” during the challenge.

Unluckily OCUnit given in XCode4 doesn’t seem to allow us to gather this kind of information. There is a solution though.

SenTestCase doesn’t have any methods that can return the results. What’s more – it is created and prepared for each test separately. That’s unfortunate.

The entry method that is called for each test is -(void)performTest:(SenTestRun *)aRun; That give’s us a hint when the test is actually triggered. But we still don’t know which one and how many of them are still left. But we can count the number of runs… information about the number of test methods in the class we can get from Class itself.

So we simply add following method to our test case:

- (void)performTest:(SenTestRun *) aRun
{
    static int performed = 0;
    static int failed = 0;
    static int totalTestCount = 0;
 
    if (totalTestCount == 0)
    {
        totalTestCount = [[[self class] testInvocations] count];
    }
 
    [super performTest:aRun];
    performed++;
    if ([aRun failureCount])
        failed++;
 
    if (performed == totalTestCount)
    {
        NSLog(@"Total tests %u failed %u", performed, failed);
    }
}

About time!

It took me a while to make this decission. I’m working with Cocoa for years. And I’ve started working on iOS from the day one – day when iPhone OS SDK beta...

It took me a while to make this decission. I’m working with Cocoa for years. And I’ve started working on iOS from the day one – day when iPhone OS SDK beta was release for the first time.

I was in my own developer heaven. I’ve connected my previous knowledge from embedded systems development with my knowledge (and yes – enthusiasm!) from Mac OS X. It worked!

Years passed and I’ve figured out that in most companies I’ve worked for I am the only iOS developer on site!

I understood that most of developers I worked with have a lot of trouble understanding how Cocoa Touch works and why it’s different.

I’ve started training courses, teaching people how to develop for iOS. But trainings are always very intense. And sometimes I just want to share with something with my students. Or work collegues. Thus – this page.

I’ll try to update it as often as I can giving you some hints how I solve everyday problems in Mac OS X and iOS development.