Skip to content

Move test repetition down to the test case level#1528

Open
harlanhaskins wants to merge 8 commits intomainfrom
harlan/getting-those-reps-in
Open

Move test repetition down to the test case level#1528
harlanhaskins wants to merge 8 commits intomainfrom
harlan/getting-those-reps-in

Conversation

@harlanhaskins
Copy link
Copy Markdown
Contributor

@harlanhaskins harlanhaskins commented Feb 5, 2026

This changes the runner such that "repeat until success" or the other repetition policies repeat only the affected test case, rather than repeating the entire test plan.

Fixes #1392
Fixes rdar://130508488

Motivation:

The previous behavior was unexpected and does not match the behavior of XCTest. This changes the behavior to align the behaviors (in the way that users expect).

Modifications:

  • Adds a configuration option requiring clients to opt in to this behavior (for now, until we change the default).
  • Updates the Runner to move the iteration into a helper function
  • Adds this helper function within _runTestCase (if opted in)
  • Replaces the plan-level iteration with the helper function (if opted out)
  • Mirrors the plan-level iteration tests to test-case level iteration tests that test the same conditions with the new behavior

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@harlanhaskins
Copy link
Copy Markdown
Contributor Author

Converting to a draft for now; there's follow-on discussions we need to have about behavioral changes before we can actually sink this repetition down

@harlanhaskins harlanhaskins force-pushed the harlan/getting-those-reps-in branch from 03ba197 to 8b09896 Compare February 24, 2026 22:18
@harlanhaskins harlanhaskins force-pushed the harlan/getting-those-reps-in branch from 8b09896 to 2f6657b Compare March 9, 2026 22:52
@harlanhaskins harlanhaskins marked this pull request as ready for review March 24, 2026 19:31
@harlanhaskins harlanhaskins force-pushed the harlan/getting-those-reps-in branch from 69ebb08 to 47a6688 Compare April 13, 2026 19:34
@stmontgomery stmontgomery added enhancement New feature or request tools integration 🛠️ Integration of swift-testing into tools/IDEs command-line experience ⌨️ enhancements to the command line interface labels Apr 17, 2026
@stmontgomery stmontgomery added this to the Swift 6.4.0 (main) milestone Apr 17, 2026
/// The value of the `--repeat-until` argument.
public var repeatUntil: String?

var usePerTestCaseRepetition: Bool = false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Can we include documentation aligning with the other Bool properties in this type?


/// Whether to perform test repetition at the plan level or on a per-test-
/// case basis.
public var shouldUseLegacyPlanLevelRepetition: Bool = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's include @_spi(Experimental) too, and that would be something we remove if the proposal becomes accepted. (This will mean initially, it will have that plus inherited @_spi(ForToolsIntegrationOnly), and the latter will remain even post-acceptance.)

/// The test case that is running on the current task, if any.
var testCase: Test.Case?

/// The current iteration of the test repetition policy.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// The current iteration of the test repetition policy.
/// The current iteration of the test repetition policy, if any.

}
}

static var currentIteration: Int? {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add documentation for this property?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// MARK: - Current test, test case, and iteration

/// - Parameters:
/// - testCase: The test case to run.
/// - step: The runner plan step associated with this test case.
/// - context: Context for the test run.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the context parameter still exists on this overload, might be an unintentional copy/paste

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or perhaps, you meant to remove the parameter from the function signature?

Comment thread Sources/Testing/Running/Runner.swift Outdated
Comment on lines +459 to +460
/// - test: The test being executed.
/// - testCase: The test case being iterated.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Params aren't in this function

Comment thread Sources/Testing/Running/Runner.swift Outdated
Comment thread Tests/TestingTests/TestCaseIterationTests.swift Outdated
Comment thread Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift Outdated
Comment thread Sources/Testing/ABI/Encoded/ABI.EncodedEvent.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command-line experience ⌨️ enhancements to the command line interface enhancement New feature or request tools integration 🛠️ Integration of swift-testing into tools/IDEs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support retry-on-failure for only the failing @Test cases

2 participants