mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Swift Testing for Unit Tests PART 1 (#5119)
* migrated a lot of unit tests to Swift Testing and added a new implementation for deferred fulfillment more tests migration Cleaned the code manually to establish some good patterns more code improvements some more code improvements removed empty tests update project * more pr suggestions and cleanups * removed the TestSetup pattern * fixing claude not reusing tests * pr suggestion + added indent rule to swiftformat so that we can prevent AIs to change that
This commit is contained in:
@@ -8,24 +8,27 @@
|
||||
|
||||
@testable import ElementX
|
||||
import Foundation
|
||||
import XCTest
|
||||
import Testing
|
||||
|
||||
class ExpiringTaskRunnerTests: XCTestCase {
|
||||
@Suite
|
||||
struct ExpiringTaskRunnerTests {
|
||||
enum ExpiringTaskTestError: Error {
|
||||
case failed
|
||||
}
|
||||
|
||||
func testSuccedingTask() async {
|
||||
@Test
|
||||
func succedingTask() async throws {
|
||||
let runner = ExpiringTaskRunner {
|
||||
try? await Task.sleep(for: .milliseconds(300))
|
||||
return true
|
||||
}
|
||||
|
||||
let result = try? await runner.run(timeout: .seconds(1))
|
||||
XCTAssertEqual(result, true)
|
||||
let result = try await runner.run(timeout: .seconds(1))
|
||||
#expect(result == true)
|
||||
}
|
||||
|
||||
func testFailingTask() async {
|
||||
@Test
|
||||
func failingTask() async {
|
||||
let runner: ExpiringTaskRunner<Result<String, ExpiringTaskTestError>> = ExpiringTaskRunner {
|
||||
try? await Task.sleep(for: .milliseconds(300))
|
||||
return .failure(.failed)
|
||||
@@ -34,20 +37,21 @@ class ExpiringTaskRunnerTests: XCTestCase {
|
||||
do {
|
||||
_ = try await runner.run(timeout: .seconds(1))
|
||||
} catch {
|
||||
XCTAssertEqual(error as? ExpiringTaskTestError, ExpiringTaskTestError.failed)
|
||||
#expect(error as? ExpiringTaskTestError == ExpiringTaskTestError.failed)
|
||||
}
|
||||
}
|
||||
|
||||
func testTimeoutTask() async {
|
||||
@Test
|
||||
func timeoutTask() async {
|
||||
let runner = ExpiringTaskRunner {
|
||||
try? await Task.sleep(for: .milliseconds(300))
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
_ = try await runner.run(timeout: .milliseconds(100))
|
||||
} catch {
|
||||
XCTAssertEqual(error as? ExpiringTaskRunnerError, ExpiringTaskRunnerError.timeout)
|
||||
#expect(error as? ExpiringTaskRunnerError == ExpiringTaskRunnerError.timeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user