Search code examples
xcodecocoaxctestxctestcasexctestexpectation

How to capture Failure logs while testing : XCTest?


Working with XCTest. While testing testresults are saved in TestSummaries.plist at path:

/Users/smriti/Library/Developer/Xcode/DerivedData/Project_name/Logs/Test/

Can anyone tell how to read contents of TestSummaries.plist file from above path?

Need to capture result data(error msg, test case, line number) from above file and write to excel in function tearDown()

Tried using

  1. NSSearchPathForDirectoriesInDomains(.AllLibrariesDirectory, .AllDomainsMask, true) -> Doesn't give desired path.

  2. NSBundle.mainBundle gives path for "Project_name/Build/Products/" not for "/Project_name/Logs/Test/"


Solution

  • You would need to write a post-test script to export the results since the TestSummaries.plist file is not available until the test run has finished.

    It's not possible to export test results during the teardown of a test since the test is only finished when teardown has been completed. Teardown actions should be actions to tie off loose ends from the test and reset the state of the application under test, rather than for post-test processing.