# Tackling UI Test Execution Time Imbalance for Xcode Parallel Testing

[Grab](https://yomu.fyi/company/grab) · Ngoc Thuyen Trinh · Mar 16, 2020

**Type:** Problem & solution

## Summary

Parallel test execution in Xcode can suffer from test time imbalance when tasks finish at significantly different times across parallel simulator workers. Analysis of Xcode scheduling logs shows that the runner groups tests by test class and dispatches all tests from the same class to a single simulator. Attempts to customize the suite by swizzling XCTestSuite fail because made-up suites initialize only after tests are dispatched. To overcome this grouping constraint, unique tokens or test names are appended to the class name component in \`-only-testing\` command-line arguments. This trick forces Xcode to treat each test as an independent class, successfully distributing individual tests across separate workers.

## Context

Xcode parallel testing groups tests by class and assigns all methods in a class to the same simulator worker, causing test execution time imbalance across parallel runners in CI pipelines.

## Approach / What changed

Modifying the test identifiers passed to the \`-only-testing\` argument of \`xcodebuild\` by inserting unique tokens or method names into the class name segment to prevent Xcode from grouping tests together.

## Takeaways

- Test time imbalance is measured as the difference between the maximum and minimum worker finish times across parallel execution instances.
- Swizzling XCTestSuite methods to split suites cannot bypass worker grouping because custom test suites initialize only after Xcode dispatches tests to workers.
- Appending unique strings to class names within \`-only-testing\` arguments causes Xcode to treat every method as a separate class, enabling single-test dispatching to free workers.

**Tags:** [CI/CD](https://yomu.fyi/topic/ci-cd), [Developer Experience](https://yomu.fyi/topic/developer-experience), [iOS](https://yomu.fyi/topic/ios), [Performance](https://yomu.fyi/topic/performance), [Testing](https://yomu.fyi/topic/testing)

[Read original post](https://engineering.grab.com/tackling-ui-test-execution-time-imbalance-for-xcode-parallel-testing)
