Skip to content

Commit 942f287

Browse files
committed
XCTest documentation from PR suggestions
1 parent 2b27308 commit 942f287

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: docs/advanced/testing.md

+40
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ let package = Package(
2222
)
2323
```
2424

25+
!!! warning
26+
Be sure to use the corresponding testing module, as failing to do so can result in Vapor test failures not being properly reported.
27+
2528
Then, add `import VaporTesting` and `import Testing` at the top of your test files. Create structs with a `@Suite` name to write test cases.
2629

2730
```swift
@@ -157,3 +160,40 @@ private func withApp(_ test: (Application) async throws -> ()) async throws {
157160
try await app.asyncShutdown()
158161
}
159162
```
163+
164+
## Using XCTest
165+
166+
If you prefer XCTest over the Swift Testing framework, or if a project requires compatibility with a more traditional approach, XCTest is fully supported. Here’s how you can get started:
167+
168+
First ensure that the `XCTVapor` module has been added to your package's test target.
169+
170+
```swift
171+
let package = Package(
172+
...
173+
dependencies: [
174+
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0")
175+
],
176+
targets: [
177+
...
178+
.testTarget(name: "AppTests", dependencies: [
179+
.target(name: "App"),
180+
.product(name: "XCTVapor", package: "vapor"),
181+
])
182+
]
183+
)
184+
```
185+
186+
Then, add `import XCTVapor` at the top of your test files. Create classes extending `XCTestCase` to write tests cases.
187+
188+
```swift
189+
import XCTVapor
190+
191+
final class MyTests: XCTestCase {
192+
func testStub() throws {
193+
// Test here.
194+
}
195+
}
196+
```
197+
198+
!!! note
199+
For newer projects or teams adopting Swift concurrency, `VaporTesting` is highly recommended due to its simplicity and integration with Vapor.

0 commit comments

Comments
 (0)