From 282cc99ae8832fd57b75d9dc5b13c2aac3c4ddbf Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Mon, 6 Nov 2023 09:00:17 -0900 Subject: [PATCH] test: clear test state in tests using SentryDependencyContainer (#3378) --- .../Helper/SentryAppStateManagerTests.swift | 1 + .../Helper/SentryFileManagerTests.swift | 1 + Tests/SentryTests/Helper/SentryLogTests.swift | 1 + .../Integrations/ANR/SentryANRTrackerTests.swift | 1 + .../SentryAppStartTrackingIntegrationTests.swift | 1 + .../SentryFramesTrackingIntegrationTests.swift | 1 + .../Networking/SentryHttpTransportTests.swift | 1 + .../Protocol/SentryEnvelopeTests.swift | 15 ++++++--------- Tests/SentryTests/SentryHubTests.swift | 1 + 9 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Tests/SentryTests/Helper/SentryAppStateManagerTests.swift b/Tests/SentryTests/Helper/SentryAppStateManagerTests.swift index 88296adeabd..2af65cfe132 100644 --- a/Tests/SentryTests/Helper/SentryAppStateManagerTests.swift +++ b/Tests/SentryTests/Helper/SentryAppStateManagerTests.swift @@ -46,6 +46,7 @@ class SentryAppStateManagerTests: XCTestCase { override func tearDown() { super.tearDown() fixture.fileManager.deleteAppState() + clearTestState() } func testStartStoresAppState() { diff --git a/Tests/SentryTests/Helper/SentryFileManagerTests.swift b/Tests/SentryTests/Helper/SentryFileManagerTests.swift index 1d17a3625f0..ae227df1b22 100644 --- a/Tests/SentryTests/Helper/SentryFileManagerTests.swift +++ b/Tests/SentryTests/Helper/SentryFileManagerTests.swift @@ -94,6 +94,7 @@ class SentryFileManagerTests: XCTestCase { sut.deleteAllFolders() sut.deleteTimestampLastInForeground() sut.deleteAppState() + clearTestState() } func testInitDoesNotOverrideDirectories() { diff --git a/Tests/SentryTests/Helper/SentryLogTests.swift b/Tests/SentryTests/Helper/SentryLogTests.swift index a0cf18e4baa..5e366a58a11 100644 --- a/Tests/SentryTests/Helper/SentryLogTests.swift +++ b/Tests/SentryTests/Helper/SentryLogTests.swift @@ -1,3 +1,4 @@ +import SentryTestUtils import XCTest class SentryLogTests: XCTestCase { diff --git a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift index ae0143664eb..0db5ee6a505 100644 --- a/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift +++ b/Tests/SentryTests/Integrations/ANR/SentryANRTrackerTests.swift @@ -45,6 +45,7 @@ class SentryANRTrackerTests: XCTestCase, SentryANRTrackerDelegate { wait(for: [fixture.threadWrapper.threadFinishedExpectation], timeout: 5) XCTAssertEqual(0, fixture.threadWrapper.threads.count) + clearTestState() } func start() { diff --git a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackingIntegrationTests.swift b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackingIntegrationTests.swift index 173f02b7a5a..d377c29c9f5 100644 --- a/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackingIntegrationTests.swift +++ b/Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackingIntegrationTests.swift @@ -30,6 +30,7 @@ class SentryAppStartTrackingIntegrationTests: NotificationCenterTestCase { fixture = Fixture() SentrySDK.setAppStartMeasurement(nil) sut = SentryAppStartTrackingIntegration() + clearTestState() } override func tearDown() { diff --git a/Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackingIntegrationTests.swift b/Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackingIntegrationTests.swift index 9af615d20b5..03d22cbb4b7 100644 --- a/Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackingIntegrationTests.swift +++ b/Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackingIntegrationTests.swift @@ -27,6 +27,7 @@ class SentryFramesTrackingIntegrationTests: XCTestCase { override func tearDown() { PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode = false + clearTestState() super.tearDown() } diff --git a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift index 675eb687d2f..29c523254f2 100644 --- a/Tests/SentryTests/Networking/SentryHttpTransportTests.swift +++ b/Tests/SentryTests/Networking/SentryHttpTransportTests.swift @@ -155,6 +155,7 @@ class SentryHttpTransportTests: XCTestCase { super.tearDown() fixture.fileManager.deleteAllEnvelopes() fixture.requestManager.waitForAllRequests() + clearTestState() } func testInitSendsCachedEnvelopes() { diff --git a/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift b/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift index 5601cf8bc83..91eb25f64ad 100644 --- a/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift +++ b/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift @@ -56,16 +56,13 @@ class SentryEnvelopeTests: XCTestCase { SentryDependencyContainer.sharedInstance().dateProvider = TestCurrentDateProvider() } - override func tearDown() { - super.tearDown() - do { - let fileManager = FileManager.default - if fileManager.fileExists(atPath: fixture.path) { - try fileManager.removeItem(atPath: fixture.path) - } - } catch { - XCTFail("Couldn't delete files.") + override func tearDownWithError() throws { + try super.tearDownWithError() + let fileManager = FileManager.default + if fileManager.fileExists(atPath: fixture.path) { + try fileManager.removeItem(atPath: fixture.path) } + clearTestState() } private let defaultSdkInfo = SentrySdkInfo(name: SentryMeta.sdkName, andVersion: SentryMeta.versionString) diff --git a/Tests/SentryTests/SentryHubTests.swift b/Tests/SentryTests/SentryHubTests.swift index 015efdbdf4f..e3064630b36 100644 --- a/Tests/SentryTests/SentryHubTests.swift +++ b/Tests/SentryTests/SentryHubTests.swift @@ -78,6 +78,7 @@ class SentryHubTests: XCTestCase { fixture.fileManager.deleteAppState() fixture.fileManager.deleteTimestampLastInForeground() fixture.fileManager.deleteAllEnvelopes() + clearTestState() } func testBeforeBreadcrumbWithoutCallbackStoresBreadcrumb() {