feat: added UI and Unit Tests

This commit is contained in:
2025-09-10 21:29:44 +02:00
parent 3ccba29620
commit 2c6537b072
4 changed files with 149 additions and 69 deletions

View File

@@ -2,40 +2,63 @@
// QuizAppUITests.swift
// QuizAppUITests
//
// Created by Paul Nowotka on 02.08.25.
// Created by Paul on 02.08.25.
//
import XCTest
final class QuizAppUITests: XCTestCase {
var app: XCUIApplication!
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false
// In UI tests its important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
app = XCUIApplication()
app.launch()
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
@MainActor
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
func testMultipleChoice() throws {
app/*@START_MENU_TOKEN@*/.buttons.containing(.staticText, identifier: "Hauptstädte").firstMatch/*[[".buttons",".containing(.staticText, identifier: \"Highscore: 7\").firstMatch",".containing(.staticText, identifier: \"Hauptstädte\").firstMatch",".otherElements.buttons[\"Hauptstädte, Highscore: 7\"]",".buttons[\"Hauptstädte, Highscore: 7\"]"],[[[-1,4],[-1,3],[-1,0,1]],[[-1,2],[-1,1]]],[2,0]]@END_MENU_TOKEN@*/.tap()
//Erscheint die erste Frage korrekt?
let q1 = app.staticTexts["Was ist die Hauptstadt von Frankreich?"]
XCTAssertTrue(q1.waitForExistence(timeout: 1))
app.buttons["Paris"].tap()
//Korrekte Auswertung?
XCTAssertTrue(app.staticTexts["✅ Richtig!"].waitForExistence(timeout: 1))
XCTAssertTrue(app.buttons["Nächste Frage"].exists)
}
func testEstimationSliderDisabledAfterSubmit() throws {
app.staticTexts["Schätzen"].tap()
// Use XCTAssert and related functions to verify your tests produce the correct results.
let slider = app.sliders.element(boundBy: 0)
XCTAssertTrue(slider.waitForExistence(timeout: 2))
slider.adjust(toNormalizedSliderPosition: 0.7)
let submit = app.buttons["Antwort abgeben"]
XCTAssertTrue(submit.exists)
submit.tap()
// Slider muss disabled sein
XCTAssertFalse(slider.isEnabled)
XCTAssertTrue(app.buttons["Nächste Frage"].waitForExistence(timeout: 2))
}
@MainActor
func testLaunchPerformance() throws {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
func testQuit() throws {
app/*@START_MENU_TOKEN@*/.buttons.containing(.staticText, identifier: "Hauptstädte").firstMatch/*[[".buttons",".containing(.staticText, identifier: \"Highscore: 7\").firstMatch",".containing(.staticText, identifier: \"Hauptstädte\").firstMatch",".otherElements.buttons[\"Hauptstädte, Highscore: 7\"]",".buttons[\"Hauptstädte, Highscore: 7\"]"],[[[-1,4],[-1,3],[-1,0,1]],[[-1,2],[-1,1]]],[2,0]]@END_MENU_TOKEN@*/.tap()
app/*@START_MENU_TOKEN@*/.buttons["Abbrechen"]/*[[".otherElements[\"Abbrechen\"].buttons.firstMatch",".otherElements.buttons[\"Abbrechen\"]",".buttons[\"Abbrechen\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
app/*@START_MENU_TOKEN@*/.buttons["Quiz verlassen"]/*[[".otherElements.buttons[\"Quiz verlassen\"]",".buttons[\"Quiz verlassen\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
let welcome_msg = app.staticTexts["Willkommen!"]
XCTAssertTrue(welcome_msg.waitForExistence(timeout: 1))
}
}