Prefix test in-front of UI test methods.

This commit is contained in:
Doug
2022-07-14 17:49:49 +01:00
committed by Doug
parent 0442342fc5
commit e6ea10f3a6
39 changed files with 404 additions and 757 deletions
@@ -18,55 +18,16 @@ import XCTest
import RiotSwiftUI
/// XCTestCase subclass to ease testing of `MockScreenState`.
/// Creates a test case for each screen state, launches the app,
/// goes to the correct screen and provides the state and key for each
/// invocation of the test.
class MockScreenTest: XCTestCase {
enum Constants {
static let defaultTimeout: TimeInterval = 3
}
class var screenType: MockScreenState.Type? {
return nil
}
class func createTest() -> MockScreenTest {
return MockScreenTest()
}
var screenState: MockScreenState?
var screenStateKey: String?
/// Launches the app with an environment variable used to disable animations.
/// Begin each test with the following code before checking the UI:
/// ```
/// app.goToScreenWithIdentifier(MockTemplateScreenState.someScreenState.title)
/// ```
class MockScreenTestCase: XCTestCase {
let app = XCUIApplication()
override class var defaultTestSuite: XCTestSuite {
let testSuite = XCTestSuite(name: NSStringFromClass(self))
guard let screenType = screenType else {
return testSuite
}
// Create a test case for each screen state
screenType.screenStates.enumerated().forEach { index, screenState in
let key = screenType.screenNames[index]
addTestFor(screenState: screenState, screenStateKey: key, toTestSuite: testSuite)
}
return testSuite
}
class func addTestFor(screenState: MockScreenState, screenStateKey: String, toTestSuite testSuite: XCTestSuite) {
let test = createTest()
test.screenState = screenState
test.screenStateKey = screenStateKey
testSuite.addTest(test)
}
open override func setUpWithError() throws {
// For every test case launch the app and go to the relevant screen
continueAfterFailure = false
app.launchEnvironment = ["IS_RUNNING_UI_TESTS": "1"]
app.launch()
guard let screenKey = screenStateKey else { fatalError("no screen") }
app.goToScreenWithIdentifier(screenKey)
}
}