2

I have a test suite in which there are many test classes each one having many tests. Now if I define

+ (void)tearDown

in any class, then it will be run after all the tests of that class only. and

- (void)tearDown

will be run after each test. I want to define a tearDown method and want it to be run after all the tests of all the classes. Fox eg, if I have 5 classes each having 7 tests each. So I want to run this tearDown function after all the 35 tests.

Udit Agarwal
  • 868
  • 9
  • 22
  • - Which test framework are you using? - Why do you need to do a final teardown? – Jon Reid Nov 23 '13 at 02:55
  • I am using sentest. And in xcode 5, my test coverage generation failed. I searched and found that we have to run __gcov_flush to get .gcda files built. To do that, I have to run this function after whole test suite. – Udit Agarwal Nov 23 '13 at 08:07

2 Answers2

0

If I understand correctly your question, you can take note of completion of each method using a global variable/flag using completion block methods like this:

+ (void)myMethod:(UIView *)exampleView completion:(void (^)(BOOL finished))completion {
    if (completion) {
        completion(finished);
    }
}

Look at this for a better explanation.

Then create a method that checks if all taskes are executed and that runs final test when needed like this:

- (void)finalTest {
    if (CHECK GLOBAL FLAG FOR COMPLETION OF OTHER TASKES) {
        // do final test
    } else {
        // repeat check after 0.1 seconds
        [self performSelector:@selector(finalTest)
               withObject:nil
               afterDelay:0.1];
    }
}
Community
  • 1
  • 1
Giuseppe Garassino
  • 2,272
  • 1
  • 27
  • 47
  • Yeah!! I can do like this but for that I will have to change my existing tests which I don't want. Can't I add some special function like teardown for whole suite? – Udit Agarwal Nov 22 '13 at 15:29
0

Since you're looking for a way to call __gcov_flush() after all tests have finished, see https://qualitycoding.org/ios-7-code-coverage/. The latest code from Google Toolbox for Mac shows how to do this using test observers, with versions for both SenTestingKit and XCTest.

Jon Reid
  • 20,545
  • 2
  • 64
  • 95