Skip to content

[SWIFT-TESTING] Feature: Add test verification lab#3

Merged
LeeDayday merged 3 commits into
mainfrom
swift-testing/sammy/verification
Jul 5, 2026
Merged

[SWIFT-TESTING] Feature: Add test verification lab#3
LeeDayday merged 3 commits into
mainfrom
swift-testing/sammy/verification

Conversation

@LeeDayday

Copy link
Copy Markdown
Contributor

Summary

This PR adds VerificationTestingLab, a Swift Package focused on verifying whether tests actually catch bugs when using Swift Testing.

The lab explores common sources of false confidence in tests, including weak assertions, false positives, flaky randomness, shared mutable state, insufficient coverage, and mutation validation.

What Changed

  • Added a new Swift Package under VerificationTestingLab/testing-lab-verification
  • Implemented small production examples:
    • ThreeSixNineGame
    • LoginValidator
    • RandomIDGenerator
    • SharedCounter
  • Added Swift Testing suites for six experiments:
    • Weak assertions
    • False positives
    • Flaky tests
    • Shared mutable state
    • Parameterized tests
    • Test validation checklist
  • Added disabled tests that demonstrate intentionally unreliable or order-dependent test cases without breaking the normal verification run
  • Added documentation:
    • VerificationTestingLab/README.md
    • Docs/verification-tests.md
  • Added a package-level .gitignore to exclude SwiftPM/Xcode build artifacts

Methodology

The lab is organized around test verification risks rather than file structure.

Each experiment asks:

  • What can make a test misleading?
  • Would this test fail if production code were intentionally broken?
  • How can the test be improved to verify behavior more directly?

The documentation includes a Mermaid diagram that maps production subjects to verification risks and stronger testing strategies.

Verification

Ran the Swift Package test suite:

cd VerificationTestingLab/testing-lab-verification
swift test

Result:

19 tests in 6 suites passed
3 disabled failure examples skipped

The disabled tests are intentional examples for flaky and order-dependent behavior.

Notes for Reviewers

  • .build, .swiftpm, and .DS_Store files are intentionally excluded from the package commit.
  • The package is not an iOS app target. It is a Swift Package designed for focused Swift Testing experiments.
  • Failure examples are represented as disabled tests so reviewers can inspect or re-enable them without making the default test run unstable.

@LeeDayday LeeDayday self-assigned this Jun 22, 2026
Comment on lines +209 to +222
func disabledFlakyExample() {
let id = RandomIDGenerator().makeID()
#expect(id == "user-1234")
}
```

It is disabled so the normal verification run remains stable, while the failing test body is still visible.

The improved design injects randomness:

```swift
let generator = RandomIDGenerator(randomizer: FixedRandomizer(1234))
#expect(generator.makeID() == "user-1234")
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Test("A weak assertion can pass while missing the exact behavior")
func weakAssertionExample() {
// 1. Run the game with a number that should produce two claps.
let result = ThreeSixNineGame().play(33)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the same code is used in the test methods below, could you move this variable to a suite property? Swift Testing creates a new suite instance for each test method, so the property won’t be shared between tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. I moved this setup into a suite property.

@Test("Mutation: returning one clap for every match would be caught")
func mutationReturningOnlyOneClapIsCaught() {
// 1. Create the system under test.
let game = ThreeSixNineGame()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a suit property

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here as well. This is now a suite property.


Tests should be independent. A suite groups tests by topic, but tests inside one suite should not depend on being run in the order they appear in the file.

## Experiments

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice👍

@x-0o0 x-0o0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from some comments I left, this looks good to me. Once you’ve resolved all the comments, feel free to merge this PR.

Welcome to the world of Testing Guardians

@LeeDayday

Copy link
Copy Markdown
Contributor Author

Thanks for the comments. I applied the same suite-property cleanup in both places. Swift Testing creates a fresh suite instance for each test, so these immutable properties keep the setup reusable without sharing state across tests.

@LeeDayday LeeDayday merged commit 939c840 into main Jul 5, 2026
@LeeDayday LeeDayday deleted the swift-testing/sammy/verification branch July 5, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants