XCTRuntimeAssertions

1.0.1

XCTest extensions to test runtime assertions and preconditions
StanfordBDHG/XCTRuntimeAssertions

What's New

1.0.1

2024-02-16T02:30:38Z

What's Changed

  • Add platform support for visionOS, macOS, watchOS, tvOS by @Supereg in #12

Full Changelog: 1.0.0...1.0.1

XCTRuntimeAssertions

Build and Test codecov DOI

Test assertions and preconditions using XCTest.

Overview

This package allows developers to test assertions and preconditions in tests using XCTest. This is done by overloading Swifts runtime assertions with functions provided by XCTRuntimeAssertions. These are always called in your System under Test. Only if requested within a unit test, their implementations are swapped to assert a runtime assertion.

Configure your System under Test

To configure your System under Test, you just need to import the XCTRuntimeAssertion package and call your runtime assertions functions as usual.

import XCTRuntimeAssertions

func foo() {
    precondition(someFooCondition, "Foo condition is unmet.")
    // ...
}

Testing Runtime Assertions

In your unit tests you can use the XCTRuntimeAssertion and XCTRuntimePrecondition functions to test a block of code for which you expect a runtime assertion to occur.

Below is a short code example demonstrating this for assertions:

try XCTRuntimeAssertion {
    assertionFailure()
}

Below is a short code example demonstrating this for preconditions:

try XCTRuntimePrecondition {
    preconditionFailure()
}

Tip

XCTRuntimeAssertion and XCTRuntimePrecondition also support the execution of async code.

Contributing

Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.

License

This project is licensed under the MIT License. See Licenses for more information.

Stanford Byers Center for Biodesign Logo Stanford Byers Center for Biodesign Logo

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Apr 14 2024 23:47:07 GMT-0900 (Hawaii-Aleutian Daylight Time)