Created
September 14, 2023 12:54
-
-
Save ncreated/6c198ce545da299b3e41cb02e95dc29e to your computer and use it in GitHub Desktop.
Basic setup for repeating tests in random order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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