Unit test results
44 days agoSometimes (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
) 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); } }