-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial documentation * Add workflow for pushing to GitHub pages * Fix tmp dir * fix script issues * only run on main branch
- Loading branch information
1 parent
e214070
commit c4f4546
Showing
8 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: "Documentation" | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
name: Build Documentation | ||
runs-on: macos-13 | ||
env: | ||
DEVELOPER_DIR: /Applications/Xcode_15.0.app/Contents/Developer | ||
GENERATED_SITE_PATH: "/tmp/_site" | ||
HOSTING_BASE_PATH: "https://liamnichols.eu/swift-fixture" | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
- name: Build Documentation | ||
run: swift package --allow-writing-to-directory "${{ env.GENERATED_SITE_PATH }}" generate-documentation --target SwiftFixture --disable-indexing --transform-for-static-hosting --hosting-base-path "${{ env.HOSTING_BASE_PATH }}" --output-path "${{ env.GENERATED_SITE_PATH }}" | ||
- name: Upload Site | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: ${{ env.GENERATED_SITE_PATH }} | ||
|
||
deploy: | ||
name: Deploy Documentation | ||
needs: build | ||
permissions: | ||
pages: write | ||
id-token: write | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ name: "Tests" | |
on: | ||
push: | ||
branches: | ||
- main | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
- main | ||
|
||
jobs: | ||
macos: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# ``SwiftFixture`` | ||
|
||
A simple framework for managing test fixtures in Swift. | ||
|
||
## Overview | ||
|
||
SwiftFixture provides a set of tools designed to help make it easy for you to instantiate and organise values of your own Swift types for use as fixtures during unit testing. | ||
|
||
To recap, a [test fixture](https://en.wikipedia.org/wiki/Test_fixture) is an environment used to consistently test our software. For example: | ||
|
||
```swift | ||
struct User { | ||
var id: UUID | ||
var name: String | ||
var createdAt: Date | ||
var isActive: Bool | ||
// ... | ||
} | ||
|
||
class SummaryTests: XCTestCase { | ||
func testSummaryForActiveUser() { | ||
let user = User(id: UUID(), name: "John", createdAt: Date(), isActive: true) | ||
|
||
let actual = getSummary(for: user) | ||
let expected = "John is currently active" | ||
|
||
XCTAssertEqual(actual, expected) | ||
} | ||
} | ||
``` | ||
|
||
In the `testSummaryForActiveUser()` example above, the `user` property is our test fixture that we rely on to test the behaviour of the `getSummary(for:)` method. Using the existing `User` initializer directly to create the fixture works, but over time you might start running into issues as your codebase matures. | ||
|
||
For example, you might already have noticed that the test is forced to reference the unused `id` and `createdAt` arguments. Additionally, if this practice was applied in multiple places, adding a new argument to the `User` initializer would require a large number of code changes across your tests, or worse, you could find yourself taking shortcuts with default values when you don't want to be. | ||
|
||
SwiftFixture aims to help provide a structure for creating fixtures that can scale with your codebase as it grows: | ||
|
||
```swift | ||
class SummaryTests: XCTestCase { | ||
let fixture = Fixture() | ||
|
||
func testSummaryForActiveUser() throws { | ||
var user = try fixture(User.self) | ||
user.isActive = true | ||
|
||
let actual = getSummary(for: user) | ||
let expected = "\(user.name) is currently active" | ||
|
||
XCTAssertEqual(actual, expected) | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Topics | ||
|
||
### Basics | ||
|
||
- ``Fixture`` | ||
|
||
### Registering Custom Types | ||
|
||
- ``FixtureProviding`` | ||
- ``ProvideFixture()`` | ||
|
||
### Misc | ||
|
||
- ``PreferredFormat`` | ||
- ``ResolutionError`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters