Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share global constants among different targets

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?

like image 766
BadmintonCat Avatar asked Oct 05 '17 08:10

BadmintonCat


1 Answers

Select the file in which you have declared your constants and update its target membership to make it available with test target

enter image description here

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.
}
like image 73
Sandeep Bhandari Avatar answered Oct 06 '22 14:10

Sandeep Bhandari