Added custom enviroment flags for unit and UI tests.

This commit is contained in:
Stefan Ceriu
2022-04-13 17:19:11 +03:00
parent d4f4f30f4e
commit e490f2838d
6 changed files with 82 additions and 11 deletions

View File

@@ -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 = "<group>"; };
72F37B5DA798C9AE436F2C2C /* AttributedStringBuilderProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedStringBuilderProtocol.swift; sourceTree = "<group>"; };
752DEC02D93AFF46BC13313A /* NavigationRouterType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationRouterType.swift; sourceTree = "<group>"; };
7D0CBC76C80E04345E11F2DB /* Application.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = "<group>"; };
7DDBF99755A9008CF8C8499E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
7FFCC48E7F701B6C24484593 /* WeakDictionaryKeyReference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakDictionaryKeyReference.swift; sourceTree = "<group>"; };
81B17DB1BC3B0C62AF84D230 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
@@ -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 */,

View File

@@ -27,9 +27,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "NO"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "NO">
<Testables>
<TestableReference
skipped = "NO">
@@ -63,6 +62,13 @@
</MacroExpansion>
<CommandLineArguments>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
key = "IS_RUNNING_UNIT_TESTS"
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"

View File

@@ -13,8 +13,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private var appCoordinator: AppCoordinator!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> 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
}
}

View File

@@ -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

View File

@@ -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()
}
}

View File

@@ -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()
}
}
}