Skip to content

Commit 9d19a2a

Browse files
test: Use targeted cleanup instead of blanket clearTestState
Replace the class-level tearDown with per-test cleanup: - AttachToTransactionStrategy tests: reset app start measurement - StandaloneTransactionStrategy tests: reset current hub - Integration tests: full clearTestState via setUpIntegrationHub - Helper tests: no cleanup needed
1 parent f525749 commit 9d19a2a

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Tests/SentryTests/Integrations/Performance/AppStartTracking/AppStartReportingStrategyTests.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ import XCTest
66

77
class AppStartReportingStrategyTests: XCTestCase {
88

9-
override func tearDown() {
10-
super.tearDown()
11-
// The integration tests modify SentryDependencyContainer global state
12-
// (debugImageProvider, framesTracker, hub), so we need the full cleanup.
13-
clearTestState()
14-
}
15-
169
private func createMeasurement(type: SentryAppStartType, duration: TimeInterval = 0.5) -> SentryAppStartMeasurement {
1710
let dateProvider = TestCurrentDateProvider()
1811
let appStart = dateProvider.date()
@@ -37,9 +30,17 @@ class AppStartReportingStrategyTests: XCTestCase {
3730
return TestHub(client: client, andScope: Scope())
3831
}
3932

33+
private func setCurrentHub() -> TestHub {
34+
let hub = createHub()
35+
SentrySDKInternal.setCurrentHub(hub)
36+
addTeardownBlock { SentrySDKInternal.setCurrentHub(nil) }
37+
return hub
38+
}
39+
4040
// MARK: - AttachToTransactionStrategy
4141

4242
func testReport_whenColdStart_shouldSetMeasurementOnGlobalStatic() throws {
43+
addTeardownBlock { SentrySDKInternal.setAppStartMeasurement(nil) }
4344
let measurement = createMeasurement(type: .cold)
4445

4546
AttachToTransactionStrategy().report(measurement)
@@ -50,6 +51,7 @@ class AppStartReportingStrategyTests: XCTestCase {
5051
}
5152

5253
func testReport_whenWarmStart_shouldSetMeasurementOnGlobalStatic() throws {
54+
addTeardownBlock { SentrySDKInternal.setAppStartMeasurement(nil) }
5355
let measurement = createMeasurement(type: .warm)
5456

5557
AttachToTransactionStrategy().report(measurement)
@@ -71,8 +73,7 @@ class AppStartReportingStrategyTests: XCTestCase {
7173
}
7274

7375
func testReport_whenColdStart_shouldCaptureTransaction() throws {
74-
let hub = createHub()
75-
SentrySDKInternal.setCurrentHub(hub)
76+
let hub = setCurrentHub()
7677
let measurement = createMeasurement(type: .cold)
7778

7879
StandaloneTransactionStrategy().report(measurement)
@@ -87,8 +88,7 @@ class AppStartReportingStrategyTests: XCTestCase {
8788
}
8889

8990
func testReport_whenWarmStart_shouldCaptureTransaction() throws {
90-
let hub = createHub()
91-
SentrySDKInternal.setCurrentHub(hub)
91+
let hub = setCurrentHub()
9292
let measurement = createMeasurement(type: .warm)
9393

9494
StandaloneTransactionStrategy().report(measurement)
@@ -102,8 +102,7 @@ class AppStartReportingStrategyTests: XCTestCase {
102102
}
103103

104104
func testReport_whenUnknownStartType_shouldNotCaptureTransaction() {
105-
let hub = createHub()
106-
SentrySDKInternal.setCurrentHub(hub)
105+
let hub = setCurrentHub()
107106
let measurement = createMeasurement(type: .unknown)
108107

109108
StandaloneTransactionStrategy().report(measurement)
@@ -112,8 +111,7 @@ class AppStartReportingStrategyTests: XCTestCase {
112111
}
113112

114113
func testReport_whenColdStart_shouldNotSetGlobalStatic() {
115-
let hub = createHub()
116-
SentrySDKInternal.setCurrentHub(hub)
114+
_ = setCurrentHub()
117115
let measurement = createMeasurement(type: .cold)
118116

119117
StandaloneTransactionStrategy().report(measurement)
@@ -124,6 +122,8 @@ class AppStartReportingStrategyTests: XCTestCase {
124122
// MARK: - StandaloneTransactionStrategy Integration Tests
125123

126124
private func setUpIntegrationHub() -> TestHub {
125+
addTeardownBlock { clearTestState() }
126+
127127
let dateProvider = TestCurrentDateProvider()
128128
SentryDependencyContainer.sharedInstance().dateProvider = dateProvider
129129

0 commit comments

Comments
 (0)