Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stanfordbdhg/xctruntimeassertions
XCTest extensions to test runtime assertions and preconditions
https://github.com/stanfordbdhg/xctruntimeassertions
assertion fatalerror precondition runtime stanford swift test xcode xctest
Last synced: 3 months ago
JSON representation
XCTest extensions to test runtime assertions and preconditions
- Host: GitHub
- URL: https://github.com/stanfordbdhg/xctruntimeassertions
- Owner: StanfordBDHG
- License: mit
- Created: 2023-03-08T01:11:00.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-15T16:06:03.000Z (5 months ago)
- Last Synced: 2024-10-30T17:21:39.473Z (3 months ago)
- Topics: assertion, fatalerror, precondition, runtime, stanford, swift, test, xcode, xctest
- Language: Swift
- Homepage: https://swiftpackageindex.com/StanfordBDHG/XCTRuntimeAssertions/documentation/xctruntimeassertions
- Size: 52.7 KB
- Stars: 1
- Watchers: 11
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Citation: CITATION.cff
Awesome Lists containing this project
README
# XCTRuntimeAssertions
[![Build and Test](https://github.com/StanfordBDHG/XCTRuntimeAssertions/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/StanfordBDHG/XCTRuntimeAssertions/actions/workflows/build-and-test.yml)
[![codecov](https://codecov.io/gh/StanfordBDHG/XCTRuntimeAssertions/branch/main/graph/badge.svg?token=PcUyqu5BOx)](https://codecov.io/gh/StanfordBDHG/XCTRuntimeAssertions)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7800545.svg)](https://doi.org/10.5281/zenodo.7800545)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FStanfordBDHG%2FXCTRuntimeAssertions%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/StanfordBDHG/XCTRuntimeAssertions)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FStanfordBDHG%2FXCTRuntimeAssertions%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/StanfordBDHG/XCTRuntimeAssertions)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.```swift
import XCTRuntimeAssertionsfunc 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:
```swift
try XCTRuntimeAssertion {
assertionFailure()
}
```Below is a short code example demonstrating this for preconditions:
```swift
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](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md) and the [contributor covenant code of conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) first.
## License
This project is licensed under the MIT License. See [Licenses](https://github.com/StanfordBDHG/XCTRuntimeAssertions/tree/main/LICENSES) for more information.
![Stanford Byers Center for Biodesign Logo](https://raw.githubusercontent.com/StanfordBDHG/.github/main/assets/biodesign-footer-light.png#gh-light-mode-only)
![Stanford Byers Center for Biodesign Logo](https://raw.githubusercontent.com/StanfordBDHG/.github/main/assets/biodesign-footer-dark.png#gh-dark-mode-only)