How to capture Failure logs while testing : XCTest?

1.7k views Asked by At

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/"

2

There are 2 answers

3
Oletha On BEST ANSWER

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.

0
Smriti10 On

Found another way of capturing test result data.

func recordFailureWithDescription(description: String, inFile filePath: String, atLine lineNumber: UInt, expected: Bool)

Above function will be called every time a failure occurs while test run and will give necessary details(error description, filename, line number) which can be written to file.