2

I need to do the pre-test config, one time setup before I run XCUITest (automation test) cases,

Example of pre-test setup: (This needs to be done once for test cycle, the output of below APIs is used in all test cases)

  1. Fetching qTest access token
  2. Fetching the qTest URLs from remote config file.

From docs I found that testBundleWillStart method of XCTestObservation protocol is ideal place to do pre-test setup.

But -testBundleWillStart method is not getting called or executed, all below listed methods of XCTestObservation are getting executed correctly.

  1. testSuiteWillStart
  2. testCaseWillStart
  3. testCaseDidFinish
  4. testSuiteDidFinish

I tried setting Principal Class in UITest info.plist but no luck, it shows following error

Test bundle Info.plist at /var/containers/Bundle/Application/BEAFB0C2-43D5-4C90-B50F-B1FF1A16BC23/MyAppUITests-Runner.app/PlugIns/MyAppUITests.xctest/Info.plist specified MyAppUItests.TestObserver for NSPrincipalClass, but no class matching that name was found.

How can I get the method testBundleWillStart executed? Any help would be appreciated.

Saif
  • 2,678
  • 2
  • 22
  • 38
  • Have you created the `TestObserver` class in your code base? – Mike Collins Apr 09 '21 at 14:18
  • I figured out the problem already, The problem was with my project name having space, it's fixed now. @MikeCollins, refer answer https://stackoverflow.com/a/67023389/3733561 – Saif Apr 09 '21 at 14:54

1 Answers1

4

Found the issue, My project name had a space, so replacing the space with _ worked.

Info about my project:

  • My project name: My App
  • My project test bundle name: My-AppUITests

Working Solution: (Replacing space with _ character)

<key>NSPrincipalClass</key>
<string>My_AppUITests.SOTestObserver</string>

Let me also share the things that seem right but still don't work:

Non-working #1: (Replacing space with - character)

<key>NSPrincipalClass</key>
<string>My-AppUITests.SOTestObserver</string> //Didn't work

Non-working #2: (Replacing project name with $(PRODUCT_NAME) environment variable)

<key>NSPrincipalClass</key>
<string>$(PRODUCT_NAME).SOTestObserver</string> //Didn't work
Saif
  • 2,678
  • 2
  • 22
  • 38