Navigation: ← Chapter 09 · Manual index · Chapter 11 →
The package test target XLKitTests exercises public APIs (workbook/sheet, CSV, images, formatting, merges, borders, file save, column ordering, etc.). Tests are @MainActor and inherit shared helpers from XLKitTestBase.
From the package root:
swift testRun one test type (XCTest filter):
swift test --filter XLKitTests.CSVTestsUse withSavedTempWorkbookSync or withSavedTempWorkbookAsync when the test must read the generated .xlsx (or assert file existence). The helper saves first, runs your closure, then deletes the temp file.
import XCTest
import XLKit
@MainActor
final class MyFeatureTests: XLKitTestBase {
func testSaveProducesFile() throws {
try withSavedTempWorkbookSync(prefix: "my-case") { workbook, url in
XCTAssertTrue(FileManager.default.fileExists(atPath: url.path))
XCTAssertEqual(workbook.getSheets().count, 1)
}
}
func testAsyncSave() async throws {
try await withSavedTempWorkbookAsync(prefix: "my-async") { workbook, url in
XCTAssertTrue(FileManager.default.fileExists(atPath: url.path))
}
}
}Use XLKitTestBase.makeUTCDate (or fixedTestDate / epochDate) instead of Date() when assertions depend on serialised values.
XLKitTestBase exposes makeThinBorderFormat(), makeMediumRedBorderFormat(), makeThickBlueBorderFormat() for consistent border tests.
The executable XLKitTestRunner builds sample workbooks and (where noted) validates them with CoreXLSX. It is for demos and CI smoke tests, not a replacement for swift test.
cd /path/to/XLKit # package root
swift run XLKitTestRunner help
swift run XLKitTestRunner no-embeds # CSV → xlsx, no images
swift run XLKitTestRunner embed # CSV + embedded images
swift run XLKitTestRunner comprehensive # broad API demo
swift run XLKitTestRunner security-demo # path restriction demo
swift run XLKitTestRunner ios-test # iOS-oriented sample output
swift run XLKitTestRunner number-formats # number format showcaseAliases such as no-images, with-embeds, demo, formats are accepted — see Sources/XLKitTestRunner/main.swift for the full switch.
Generated files usually land under Test-Workflows/ (or the project root for some scenarios). See Sources/XLKitTestRunner/README.md for paths per command.
- Copy
Sources/XLKitTestRunner/Templates/TestGeneratorTemplate.swiftto a new file. - Implement your generator using
XLKitAPIs. - Register the subcommand in
main.swiftand extendprintHelp().
Workflows live in .github/workflows/:
| Workflow | Role |
|---|---|
build.yml |
macOS build + unit tests + swift run XLKitTestRunner smoke (help, embed); duplicate job with Swift tools 6.0; iOS simulator build + tests |
codeql.yml |
CodeQL security analysis |
cli-*.yml |
Focused CLI runs (e.g. no-embeds, embed, generic, iOS, number-formats) |
Pushes that touch only docs/assets may skip builds — see each workflow’s paths-ignore.
Project formatting expectations are described in .cursorrules and enforced via swift-format using .swift-format (4 spaces, 120 columns, grouped imports, trailing commas, etc.).
Format sources from the repo root (with swift-format installed):
swift-format format --configuration .swift-format -i .Use the same configuration in Xcode or CI so diffs stay consistent.
Tests/README.md— Test layout and conventionsSources/XLKitTestRunner/README.md— CLI details- Chapter 12 — API reference — Public surface under test