.agents/skills/swift-testing-expert/references/parallelization-and-isolation.md
Use this file when tests are flaky in CI, have hidden ordering dependencies, or need to scale execution speed safely.
import Testing
enum SharedStore {
static var counter = 0
}
@Test func incrementsCounter() {
SharedStore.counter += 1
#expect(SharedStore.counter >= 1)
}
@Test func expectsFreshCounter() {
// Flaky if tests run in parallel or random order.
#expect(SharedStore.counter == 0)
}
import Testing
struct CounterStore {
var counter = 0
mutating func increment() { counter += 1 }
}
@Test func isolatedCounter() {
var store = CounterStore()
store.increment()
#expect(store.counter == 1)
}
.serialized as a targeted tool.serialized to suites when tests must run one-at-a-time.import Testing
@Suite(.serialized)
struct LegacyDatabaseTests {
@Test func migrationStepA() { #expect(true) }
@Test func migrationStepB() { #expect(true) }
}