I have some global constants in a project:
// DemoACIs.swift
let DEMO_TEST_MENU_SCREEN_VIEW_ACI = "test_menu_screen_view"
let DEMO_TEST_MENU_SCREEN_TITLE_LABEL_ACI = "test_menu_screen_title_label"
let DEMO_TEST_MENU_SCREEN_BUTTON1_ACI = "test_menu_screen_button1"
etc.
And I want to refer them in another Swift-based target in Xcode (a UI test target in this case) ...
// TestMenuScreenViewProxy.swift
import Foundation
import XCTest
class TestMenuScreenViewProxy
{
    internal var view:XCUIElement { return app.otherElements[DEMO_TEST_MENU_SCREEN_VIEW_ACI] }
    internal var titleLabel:XCUIElement { return app.textFields[DEMO_TEST_MENU_SCREEN_TITLE_LABEL_ACI] }
    internal var button1:XCUIElement { return app.buttons[DEMO_TEST_MENU_SCREEN_BUTTON1_ACI] }
}
Of course this doesn't work. The constants aren't found in the test target. How can I make them accessible in that target?
Select the file in which you have declared your constants and update its target membership to make it available with test target

Here is a sample code
import Foundation
class Constants {
    static let test = "ABCD"
}
Changed its target membership to make it available in test target
Now in test target
override func setUp() {
    super.setUp()
    let c  = Constants.test
    // Put setup code here. This method is called before the invocation of each test method in the class.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With