Skip to content

Instantly share code, notes, and snippets.

@ncreated
Created September 14, 2023 12:54
Show Gist options
  • Save ncreated/6c198ce545da299b3e41cb02e95dc29e to your computer and use it in GitHub Desktop.
Save ncreated/6c198ce545da299b3e41cb02e95dc29e to your computer and use it in GitHub Desktop.
Basic setup for repeating tests in random order
class FlakyTests: XCTestCase {
struct FlakySuite {
let testCase: XCTestCase
let selectors: [Selector]
}
let suites: [FlakySuite] = [
FlakySuite(
testCase: CrashContextProviderTests(),
selectors: [
#selector(CrashContextProviderTests.testWhenTrackingConsentValueChangesInConsentProvider_thenCrashContextProviderNotifiesNewContext),
#selector(CrashContextProviderTests.testWhenNewRUMView_thenItNotifiesNewCrashContext),
#selector(CrashContextProviderTests.testWhenRUMViewReset_thenItNotifiesNewCrashContext),
#selector(CrashContextProviderTests.testWhenNewRUMSessionStateIsSentThroughMessageBus_thenItNotifiesNewCrashContext),
]
),
FlakySuite(
testCase: RUMMonitorTests(),
selectors: [
#selector(RUMMonitorTests.testGivenRegisteredCrashReporter_whenRUMViewEventIsSend_itIsUpdatedInCurrentCrashContext)
]
),
FlakySuite(
testCase: TracerTests(),
selectors: [
#selector(TracerTests.testItInjectsSpanContextWithB3HTTPHeadersWriter_usingMultipleHeaders)
]
),
FlakySuite(
testCase: RUMInternalProxyTests(),
selectors: [
#selector(RUMInternalProxyTests.testProxyRecordsCustomResourceMetrics)
]
)
]
func testRandom() throws {
let suite = suites.randomElement()!
let selector = suite.selectors.randomElement()!
print("❄️ Testing: \(type(of: suite.testCase))\(selector)")
suite.testCase.setUp()
suite.testCase.performSelector(onMainThread: selector, with: nil, waitUntilDone: true)
suite.testCase.tearDown()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment