简体   繁体   中英

How to flush coverage data when my test cause app crash - For ios app

I want to get the code coverage of my tests. So I set the settings, build an app with .gcno files and run it on simulator.

It can get the coverage data successfully if there is no crash issue.

But if the app crashed, I will get nothing.

So how can I get the code coverage data when the app crash?

In my thought, this is because it will not call __gcov_flush() method when app crash. I only add app does not run in background to my plist file, so __gcov_flush() is called only at the time I press Home button.

Is there any way to call __gcov_flush() before the app crash?

I found way by myself.

Apple provide NSSetUncaughtExceptionHandler() method for app. We can add our own handler before app crash.

So we can call __gcov_flush() in this function.

#import <objc/runtime.h>
extern void __gcov_flush();
// in the exception handler function, call flush like this:
if(__gcov_flush){
    __gcov_flush();
}

DONE!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM