Skip to content

Commit

Permalink
Add first tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer committed Jul 19, 2023
1 parent 57f3e38 commit b63aaff
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 97 deletions.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let package = Package(
name: "SpeziTests",
dependencies: [
.target(name: "Spezi"),
.target(name: "XCTSpezi"),
.product(name: "XCTRuntimeAssertions", package: "XCTRuntimeAssertions")
]
)
Expand Down
24 changes: 1 addition & 23 deletions Sources/Spezi/Standard/StandardPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,7 @@ public class _StandardPropertyWrapper<Constraint>: AnyStandardPropertyWrapper {


/// Refer to ``Component/StandardActor`` for information on how to use the `@StandardActor` property wrapper. Do not use the `_StandardPropertyWrapper` directly.
public init(_ constraint: Constraint.Type = Constraint.self) {
guard Constraint.self is any Standard.Type else {
preconditionFailure(
"""
The \(String(describing: Constraint.self)) constraint does not conform to `Standard`.
Ensure that your constraint type conforms to the `Standard` protocol:
```swift
protocol ExampleConstraint: Standard {
// ...
}
class ExampleComponent: Component {
@StandardActor var standard: any ExampleConstraint
// ...
}
```
"""
)
}
}
public init(_ constraint: Constraint.Type = Constraint.self) { }


func inject<S: Standard>(standard: S) {
Expand Down
74 changes: 74 additions & 0 deletions Tests/SpeziTests/StandardTests/StandardConstraintTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// This source file is part of the Stanford Spezi open-source project
//
// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
//
// SPDX-License-Identifier: MIT
//

@testable import Spezi
import SwiftUI
import XCTest
import XCTRuntimeAssertions


private protocol ExampleConstraint: Standard {
func betterFulfill(expectation: XCTestExpectation)
}


extension MockStandard: ExampleConstraint {

Check failure on line 20 in Tests/SpeziTests/StandardTests/StandardConstraintTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

File Types Order Violation: An 'extension' should not be placed amongst the file type(s) 'main_type' (file_types_order)
func betterFulfill(expectation: XCTestExpectation) {
fulfill(expectation: expectation)
}
}


final class StandardConstraintTests: XCTestCase {
final class StandardConstraintTestComponent: Component {
@StandardActor private var standard: any ExampleConstraint

let expectation: XCTestExpectation


init(expectation: XCTestExpectation) {
self.expectation = expectation
}


func configure() {
Task {
await standard.betterFulfill(expectation: expectation)
}
}
}

class StandardConstraintTestApplicationDelegate: SpeziAppDelegate {

Check failure on line 46 in Tests/SpeziTests/StandardTests/StandardConstraintTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Type Name Violation: Type name 'StandardConstraintTestApplicationDelegate' should be between 3 and 40 characters long (type_name)
let expectation: XCTestExpectation


override var configuration: Configuration {
Configuration(standard: MockStandard()) {
StandardConstraintTestComponent(expectation: expectation)
}
}


init(expectation: XCTestExpectation) {
self.expectation = expectation
}
}


func testStandardConstraint() async throws {
let expectation = XCTestExpectation(description: "Component")
expectation.assertForOverFulfill = true

let standardConstraintTestApplicationDelegate = await StandardConstraintTestApplicationDelegate(

Check failure on line 67 in Tests/SpeziTests/StandardTests/StandardConstraintTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Identifier Name Violation: Variable name 'standardConstraintTestApplicationDelegate' should be between 3 and 40 characters long (identifier_name)
expectation: expectation
)
_ = await standardConstraintTestApplicationDelegate.spezi

await fulfillment(of: [expectation], timeout: 0.01)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import XCTest
import XCTRuntimeAssertions


final class StandardTests: XCTestCase {
final class StandardInjectionTests: XCTestCase {
final class StandardInjectionTestComponent: Component {
@StandardActor var standard: MockStandard

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,74 +54,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Account"
BuildableName = "Account"
BlueprintName = "Account"
ReferencedContainer = "container:../..">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Spezi"
BuildableName = "Spezi"
BlueprintName = "Spezi"
ReferencedContainer = "container:../..">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Contact"
BuildableName = "Contact"
BlueprintName = "Contact"
ReferencedContainer = "container:../..">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FHIR"
BuildableName = "FHIR"
BlueprintName = "FHIR"
ReferencedContainer = "container:../..">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "HealthKitDataSource"
BuildableName = "HealthKitDataSource"
BlueprintName = "HealthKitDataSource"
ReferencedContainer = "container:../..">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "LocalStorage"
BuildableName = "LocalStorage"
BlueprintName = "LocalStorage"
ReferencedContainer = "container:../..">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Onboarding"
BuildableName = "Onboarding"
BlueprintName = "Onboarding"
ReferencedContainer = "container:../..">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SecureStorage"
BuildableName = "SecureStorage"
BlueprintName = "SecureStorage"
ReferencedContainer = "container:../..">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "XCTRuntimeAssertions"
BuildableName = "XCTRuntimeAssertions"
BlueprintName = "XCTRuntimeAssertions"
ReferencedContainer = "container:../..">
</BuildableReference>
</CodeCoverageTargets>
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:UITests.xcodeproj/TestApp.xctestplan"
Expand All @@ -139,11 +72,6 @@
BlueprintName = "TestAppUITests"
ReferencedContainer = "container:UITests.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "HealthKitTests">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
Expand Down

0 comments on commit b63aaff

Please sign in to comment.