Xcode5 Code Coverage (from cmd-line for CI builds)

后端 未结 6 1601
广开言路
广开言路 2020-12-14 03:48

How can I generate code coverage with Xcode 5 and iOS7?

Prior to upgrading I was getting code coverage just fine. Now I can\'t see any *.gcda files being produced.

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 04:39

    With the information from here I was able to craft this version which is the least invasive I could think of. Just add to your unit tests and run the tests as normal. The ZZZ ensures it is the last run suite of tests.

    I had to ensure I added the GCC_GENERATE_TEST_COVERAGE_FILES and GCC_GENERATE_TEST_COVERAGE_FILES compiler flags to my test unit target too to get the coverage out.

    //
    //  Created by Michael May
    //
    
    #import 
    
    @interface ZZZCodeCoverageFixForUnitTests : SenTestCase
    
    @end
    
    @implementation ZZZCodeCoverageFixForUnitTests
    
    // This must run last
    
    extern void __gcov_flush();
    
    -(void)testThatIsntReallyATest
    {
        NSLog(@"FLUSHING GCOV FILES");
    
        __gcov_flush();
    }
    
    
    @end
    

    Edit, or another approach by Jasper:

    I stripped the VATestObserver from the other answer down to this:

    @interface VATestObserver : SenTestLog
    @end
    
    @implementation VATestObserver
    
    extern void __gcov_flush(void);
    
    - (void)applicationWillTerminate:(UIApplication*)application
    {
       __gcov_flush();
      [super applicationWillTerminate:application];
    }
    
    @end
    

提交回复
热议问题