diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 71c1565af..aa0c8cb02 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -68,6 +68,7 @@ 68AC3C84E2B438036B174E30 /* EmoteRoomTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 471EB7D96AFEA8D787659686 /* EmoteRoomTimelineView.swift */; }; 6F2AB43A1EFAD8A97AF41A15 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 5986E300FC849DEAB2EE7AEB /* Introspect */; }; 7002C55A4C917F3715765127 /* MediaProviderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = C888BCD78E2A55DCE364F160 /* MediaProviderProtocol.swift */; }; + 7405B4824D45BA7C3D943E76 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0CBC76C80E04345E11F2DB /* Application.swift */; }; 7434A7F02D587A920B376A9A /* LoginScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A43964330459965AF048A8C /* LoginScreenViewModelTests.swift */; }; 7684092532FBC71B73916441 /* RoundedToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B4238D6EB22C0F9D7A2EEC9 /* RoundedToastView.swift */; }; 77D7DAA41AAB36800C1F2E2D /* RoomTimelineProviderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 095AED4CF56DFF3EB7BB84C8 /* RoomTimelineProviderProtocol.swift */; }; @@ -216,6 +217,7 @@ 71BC7CA1BC1041E93077BBA1 /* HomeScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeScreenModels.swift; sourceTree = ""; }; 72F37B5DA798C9AE436F2C2C /* AttributedStringBuilderProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedStringBuilderProtocol.swift; sourceTree = ""; }; 752DEC02D93AFF46BC13313A /* NavigationRouterType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationRouterType.swift; sourceTree = ""; }; + 7D0CBC76C80E04345E11F2DB /* Application.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = ""; }; 7DDBF99755A9008CF8C8499E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 7FFCC48E7F701B6C24484593 /* WeakDictionaryKeyReference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakDictionaryKeyReference.swift; sourceTree = ""; }; 81B17DB1BC3B0C62AF84D230 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; @@ -568,6 +570,7 @@ 951A66D15CD44C0EACE4A951 /* Sources */ = { isa = PBXGroup; children = ( + 7D0CBC76C80E04345E11F2DB /* Application.swift */, A069578069541F94F2AF016C /* ElementXUITests.swift */, 0CCEAA8205BCCCB8DBE01724 /* ElementXUITestsLaunchTests.swift */, 4D6E4C37E9F0E53D3DF951AC /* HomeScreenUITests.swift */, @@ -1032,6 +1035,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7405B4824D45BA7C3D943E76 /* Application.swift in Sources */, 20563476E4766B9C3035E461 /* ElementXUITests.swift in Sources */, 4E50727077B53D26A7C3E504 /* ElementXUITestsLaunchTests.swift in Sources */, 9DC5FB22B8F86C3B51E907C1 /* HomeScreenUITests.swift in Sources */, diff --git a/ElementX.xcodeproj/xcshareddata/xcschemes/ElementX.xcscheme b/ElementX.xcodeproj/xcshareddata/xcschemes/ElementX.xcscheme index 85ec0fa4a..2acbdd518 100644 --- a/ElementX.xcodeproj/xcshareddata/xcschemes/ElementX.xcscheme +++ b/ElementX.xcodeproj/xcshareddata/xcschemes/ElementX.xcscheme @@ -27,9 +27,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - codeCoverageEnabled = "YES" onlyGenerateCoverageForSpecifiedTargets = "NO" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "NO"> @@ -63,6 +62,13 @@ + + + + Bool { + if isRunningUnitTests { + return true + } + + if isRunningUITests { + // Bootstrap a different version of the application + return true + } + appCoordinator = AppCoordinator() appCoordinator.start() return true } + + private var isRunningUnitTests: Bool { + #if DEBUG + ProcessInfo.processInfo.environment["IS_RUNNING_UNIT_TESTS"] == "1" + #else + false + #endif + } + + private var isRunningUITests: Bool { + #if DEBUG + ProcessInfo.processInfo.environment["IS_RUNNING_UI_TESTS"] == "1" + #else + false + #endif + } } diff --git a/ElementX/SupportingFiles/target.yml b/ElementX/SupportingFiles/target.yml index 633a5197b..ce1f2df62 100644 --- a/ElementX/SupportingFiles/target.yml +++ b/ElementX/SupportingFiles/target.yml @@ -1,5 +1,31 @@ name: ElementX +schemes: + ElementX: + analyze: + config: Debug + archive: + config: Release + build: + targets: + ElementX: + - running + - testing + - profiling + - analyzing + - archiving + profile: + config: Release + run: + config: Debug + test: + config: Debug + environmentVariables: + IS_RUNNING_UNIT_TESTS: "1" + targets: + - UnitTests + - UITests + targets: ElementX: type: application @@ -34,12 +60,6 @@ targets: else echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint" fi - - scheme: - gatherCoverageData: true - testTargets: - - UnitTests - - UITests dependencies: - package: MatrixRustSDK diff --git a/UITests/Sources/Application.swift b/UITests/Sources/Application.swift new file mode 100644 index 000000000..8ddab7dbc --- /dev/null +++ b/UITests/Sources/Application.swift @@ -0,0 +1,17 @@ +// +// Application.swift +// UITests +// +// Created by Stefan Ceriu on 13/04/2022. +// Copyright © 2022 element.io. All rights reserved. +// + +import XCTest + +struct Application { + func launch() { + let app = XCUIApplication() + app.launchEnvironment = ["IS_RUNNING_UI_TESTS": "1"] + app.launch() + } +} diff --git a/UITests/Sources/ElementXUITests.swift b/UITests/Sources/ElementXUITests.swift index 196619b6f..5f739ebd9 100644 --- a/UITests/Sources/ElementXUITests.swift +++ b/UITests/Sources/ElementXUITests.swift @@ -24,8 +24,7 @@ class ElementXUITests: XCTestCase { func testExample() throws { // UI tests must launch the application that they test. - let app = XCUIApplication() - app.launch() + Application().launch() // Use recording to get started writing UI tests. // Use XCTAssert and related functions to verify your tests produce the correct results. @@ -35,7 +34,7 @@ class ElementXUITests: XCTestCase { if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { // This measures how long it takes to launch your application. measure(metrics: [XCTApplicationLaunchMetric()]) { - XCUIApplication().launch() + Application().launch() } } }