Skip to content

Commit c6773e5

Browse files
authored
chore: Move breadcrumb tests to UITest (#3038)
* Move breadcrumb tests to UITest * Update InfoForBreadcrumbController.swift
1 parent cd39d58 commit c6773e5

File tree

7 files changed

+116
-46
lines changed

7 files changed

+116
-46
lines changed

Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
D8D7BB4E27501B9400044146 /* SpanObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D7BB4D27501B9400044146 /* SpanObserver.swift */; };
9090
D8DBDA76274D591F00007380 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DBDA75274D591F00007380 /* TableViewController.swift */; };
9191
D8DBDA78274D5FC400007380 /* SplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DBDA77274D5FC400007380 /* SplitViewController.swift */; };
92+
D8F01DEA2A1376B5008F4996 /* InfoForBreadcrumbController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F01DE92A1376B5008F4996 /* InfoForBreadcrumbController.swift */; };
9293
D8F3D052274E572F00B56F8C /* DSNStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F3D04F274E572F00B56F8C /* DSNStorage.swift */; };
9394
D8F3D053274E572F00B56F8C /* DSNStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F3D04F274E572F00B56F8C /* DSNStorage.swift */; };
9495
D8F3D054274E572F00B56F8C /* RandomErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F3D051274E572F00B56F8C /* RandomErrors.swift */; };
@@ -332,6 +333,8 @@
332333
D8D7BB4D27501B9400044146 /* SpanObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpanObserver.swift; sourceTree = "<group>"; };
333334
D8DBDA75274D591F00007380 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
334335
D8DBDA77274D5FC400007380 /* SplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = "<group>"; };
336+
D8F01DE92A1376B5008F4996 /* InfoForBreadcrumbController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoForBreadcrumbController.swift; sourceTree = "<group>"; };
337+
D8F01DF02A1377D0008F4996 /* SentryExposure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryExposure.h; sourceTree = "<group>"; };
335338
D8F3D04F274E572F00B56F8C /* DSNStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSNStorage.swift; sourceTree = "<group>"; };
336339
D8F3D051274E572F00B56F8C /* RandomErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomErrors.swift; sourceTree = "<group>"; };
337340
D8F3D056274E574200B56F8C /* LoremIpsumViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoremIpsumViewController.swift; sourceTree = "<group>"; };
@@ -544,6 +547,7 @@
544547
84FB811F283EEDB900F3A94A /* PerformanceViewController.swift */,
545548
0AABE2E928855FF80057ED69 /* PermissionsViewController.swift */,
546549
D8C33E1E29FBB1F70071B75A /* UIEventBreadcrumbsController.swift */,
550+
D8F01DE92A1376B5008F4996 /* InfoForBreadcrumbController.swift */,
547551
);
548552
path = ViewControllers;
549553
sourceTree = "<group>";
@@ -560,6 +564,7 @@
560564
D8D7BB4D27501B9400044146 /* SpanObserver.swift */,
561565
84FB812C2840021B00F3A94A /* iOS-Swift-Bridging-Header.h */,
562566
7B5525B22938B5B5006A2932 /* DiskWriteException.swift */,
567+
D8F01DF02A1377D0008F4996 /* SentryExposure.h */,
563568
);
564569
path = Tools;
565570
sourceTree = "<group>";
@@ -885,6 +890,7 @@
885890
637AFDAA243B02760034958B /* AppDelegate.swift in Sources */,
886891
D8F57BC527BBD787000D09D4 /* CoreDataViewController.swift in Sources */,
887892
D8D7BB4E27501B9400044146 /* SpanObserver.swift in Sources */,
893+
D8F01DEA2A1376B5008F4996 /* InfoForBreadcrumbController.swift in Sources */,
888894
D8DBDA76274D591F00007380 /* TableViewController.swift in Sources */,
889895
D8C33E1F29FBB1F70071B75A /* UIEventBreadcrumbsController.swift in Sources */,
890896
8E8C57AF25EF16E6001CEEFA /* TraceTestViewController.swift in Sources */,

Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,53 @@
223223
</objects>
224224
<point key="canvasLocation" x="2726" y="-625"/>
225225
</scene>
226+
<!--Info For Breadcrumb Controller-->
227+
<scene sceneID="arS-SB-tPi">
228+
<objects>
229+
<viewController id="baS-wm-UQo" customClass="InfoForBreadcrumbController" customModule="iOS_Swift" customModuleProvider="target" sceneMemberID="viewController">
230+
<view key="view" contentMode="scaleToFill" id="kuq-y5-xKM">
231+
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
232+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
233+
<subviews>
234+
<button opaque="NO" tag="1" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gz6-bT-PrL">
235+
<rect key="frame" x="65" y="85" width="190" height="35"/>
236+
<accessibility key="accessibilityConfiguration" identifier="extractInfoButton"/>
237+
<state key="normal" title="Button"/>
238+
<buttonConfiguration key="configuration" style="plain" title="Extract Info from view"/>
239+
<connections>
240+
<action selector="buttonPressed:" destination="baS-wm-UQo" eventType="touchUpInside" id="PXn-G1-6hu"/>
241+
</connections>
242+
</button>
243+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="j1U-nc-cGt">
244+
<rect key="frame" x="16" y="316" width="288" height="0.0"/>
245+
<accessibility key="accessibilityConfiguration" identifier="infoLabel"/>
246+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
247+
<nil key="textColor"/>
248+
<nil key="highlightedColor"/>
249+
</label>
250+
</subviews>
251+
<viewLayoutGuide key="safeArea" id="ddq-ee-7Ns"/>
252+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
253+
<accessibility key="accessibilityConfiguration" identifier="SOME IDENTIFIER"/>
254+
<constraints>
255+
<constraint firstItem="j1U-nc-cGt" firstAttribute="centerY" secondItem="ddq-ee-7Ns" secondAttribute="centerY" id="82P-hx-kSu"/>
256+
<constraint firstItem="j1U-nc-cGt" firstAttribute="centerX" secondItem="ddq-ee-7Ns" secondAttribute="centerX" id="Wfx-cx-GyP"/>
257+
<constraint firstItem="ddq-ee-7Ns" firstAttribute="trailing" secondItem="j1U-nc-cGt" secondAttribute="trailing" constant="16" id="lNx-HO-514"/>
258+
<constraint firstItem="j1U-nc-cGt" firstAttribute="leading" secondItem="ddq-ee-7Ns" secondAttribute="leading" constant="16" id="qpD-rY-i4q"/>
259+
<constraint firstItem="Gz6-bT-PrL" firstAttribute="top" secondItem="ddq-ee-7Ns" secondAttribute="top" constant="21" id="tIx-31-b6h"/>
260+
<constraint firstItem="Gz6-bT-PrL" firstAttribute="centerX" secondItem="ddq-ee-7Ns" secondAttribute="centerX" id="ufo-QO-Dwx"/>
261+
</constraints>
262+
</view>
263+
<navigationItem key="navigationItem" id="HVa-fh-O6F"/>
264+
<connections>
265+
<outlet property="button" destination="Gz6-bT-PrL" id="ZR6-lQ-Uj5"/>
266+
<outlet property="label" destination="j1U-nc-cGt" id="xgx-T0-PVu"/>
267+
</connections>
268+
</viewController>
269+
<placeholder placeholderIdentifier="IBFirstResponder" id="CJw-J7-n7w" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
270+
</objects>
271+
<point key="canvasLocation" x="995.625" y="-1275"/>
272+
</scene>
226273
<!--Split View Controller-->
227274
<scene sceneID="6Nq-cD-DlA">
228275
<objects>
@@ -508,38 +555,48 @@
508555
</connections>
509556
</button>
510557
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ckT-1E-GWZ">
511-
<rect key="frame" x="0.0" y="42" width="152" height="28"/>
558+
<rect key="frame" x="0.0" y="33.5" width="152" height="28"/>
512559
<fontDescription key="fontDescription" type="system" pointSize="13"/>
513560
<state key="normal" title="Close SDK"/>
514561
<connections>
515562
<action selector="close:" destination="VqS-l1-kwe" eventType="touchUpInside" id="UwB-2M-pCr"/>
516563
</connections>
517564
</button>
518565
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rpD-Rf-xbz">
519-
<rect key="frame" x="0.0" y="84" width="152" height="28"/>
566+
<rect key="frame" x="0.0" y="67" width="152" height="28"/>
520567
<fontDescription key="fontDescription" type="system" pointSize="13"/>
521568
<state key="normal" title="ANR fully blocking"/>
522569
<connections>
523570
<action selector="anrFullyBlocking:" destination="VqS-l1-kwe" eventType="touchUpInside" id="PLh-oH-8oF"/>
524571
</connections>
525572
</button>
526573
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2e4-48-rLl">
527-
<rect key="frame" x="0.0" y="126" width="152" height="28"/>
574+
<rect key="frame" x="0.0" y="101" width="152" height="28"/>
528575
<fontDescription key="fontDescription" type="system" pointSize="13"/>
529576
<state key="normal" title="ANR filling run loop"/>
530577
<connections>
531578
<action selector="anrFillingRunLoop:" destination="VqS-l1-kwe" eventType="touchUpInside" id="ON6-DV-3Tz"/>
532579
</connections>
533580
</button>
534581
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="F0l-xf-cQd">
535-
<rect key="frame" x="0.0" y="168" width="152" height="28"/>
582+
<rect key="frame" x="0.0" y="134.5" width="152" height="28"/>
536583
<fontDescription key="fontDescription" type="system" pointSize="13"/>
537584
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
538585
<state key="normal" title="Start 100 threads"/>
539586
<connections>
540587
<action selector="start100Threads:" destination="VqS-l1-kwe" eventType="touchUpInside" id="9KO-KS-85G"/>
541588
</connections>
542589
</button>
590+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Evt-B9-zEC">
591+
<rect key="frame" x="0.0" y="168" width="152" height="28"/>
592+
<accessibility key="accessibilityConfiguration" identifier="breadcrumbInfoButton"/>
593+
<fontDescription key="fontDescription" type="system" pointSize="13"/>
594+
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
595+
<state key="normal" title="Breadcrumb info test"/>
596+
<connections>
597+
<segue destination="baS-wm-UQo" kind="show" id="P5B-LG-XhB"/>
598+
</connections>
599+
</button>
543600
</subviews>
544601
</stackView>
545602
</subviews>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import <Foundation/Foundation.h>
2+
#import <UIKit/UIKit.h>
3+
4+
@interface SentryBreadcrumbTracker : NSObject
5+
6+
+ (NSDictionary *)extractDataFromView:(UIView *)view;
7+
8+
@end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#import "SentryBenchmarking.h"
2+
#import "SentryExposure.h"
23
#import <Sentry/PrivateSentrySDKOnly.h>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
import Sentry
3+
import UIKit
4+
5+
class InfoForBreadcrumbController: UIViewController {
6+
7+
@IBOutlet var button: UIButton!
8+
@IBOutlet var label: UILabel!
9+
10+
@IBAction func buttonPressed(_ sender: Any) {
11+
guard let view = self.view,
12+
let viewInfo = SentryBreadcrumbTracker.extractData(from: view),
13+
let buttonInfo = SentryBreadcrumbTracker.extractData(from: button)
14+
else {
15+
label?.text = "ERROR"
16+
return
17+
}
18+
19+
let hasCorrectData = String(describing: view) == viewInfo["view"] as? String &&
20+
viewInfo["tag"] == nil &&
21+
viewInfo["accessibilityIdentifier"] as? String == "SOME IDENTIFIER" &&
22+
viewInfo["title"] == nil &&
23+
buttonInfo["tag"] as? Int == 1 &&
24+
buttonInfo["accessibilityIdentifier"] as? String == "extractInfoButton" &&
25+
buttonInfo["title"] as? String == button.title(for: .normal)
26+
27+
label?.text = hasCorrectData ? [viewInfo, buttonInfo].debugDescription : "ERROR"
28+
}
29+
}

Samples/iOS-Swift/iOS-SwiftUITests/UIEventBreadcrumbTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ class UIEventBreadcrumbTests: XCTestCase {
3434
app.staticTexts["textFieldEndChanging:"].waitForExistence("textFieldEndChanging: not called")
3535
}
3636

37+
func testExtractInfoFromView() {
38+
app.buttons["Extra"].tap()
39+
app.buttons["breadcrumbInfoButton"].tap()
40+
app.buttons["extractInfoButton"].waitForExistence("Extract Info Button not found")
41+
app.buttons["extractInfoButton"].tap()
42+
43+
let info = app.staticTexts["infoLabel"].label
44+
45+
XCTAssertNotEqual(info, "ERROR")
46+
}
47+
3748
func waitForExistenceOfMainScreen() {
3849
app.waitForExistence( "Home Screen doesn't exist.")
3950
}

Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,48 +60,6 @@ class SentryBreadcrumbTrackerTests: XCTestCase {
6060

6161
clearTestState()
6262
}
63-
64-
func testExtractDataFrom_View() {
65-
let view = UIView()
66-
let result = Dynamic(SentryBreadcrumbTracker.self).extractDataFromView(view) as [String: Any?]?
67-
68-
XCTAssertEqual(result?["view"] as? String, String(describing: view))
69-
XCTAssertNil(result?["title"] as Any?)
70-
XCTAssertNil(result?["tag"] as Any?)
71-
XCTAssertNil(result?["accessibilityIdentifier"] as Any?)
72-
}
73-
74-
func testExtractDataFrom_ViewWith_Tag_accessibilityIdentifier() {
75-
let view = UIView()
76-
view.tag = 2
77-
view.accessibilityIdentifier = "SOME IDENTIFIER"
78-
79-
let result = Dynamic(SentryBreadcrumbTracker.self).extractDataFromView(view) as [String: Any?]?
80-
81-
XCTAssertEqual(result?["view"] as? String, String(describing: view))
82-
XCTAssertEqual(result?["tag"] as? Int, 2)
83-
XCTAssertEqual(result?["accessibilityIdentifier"] as? String, "SOME IDENTIFIER")
84-
XCTAssertNil(result?["title"] as Any?)
85-
}
86-
87-
func testExtractDataFrom_ButtonWith_Title() {
88-
let view = UIButton()
89-
view.setTitle("BUTTON TITLE", for: .normal)
90-
91-
let result = Dynamic(SentryBreadcrumbTracker.self).extractDataFromView(view) as [String: Any?]?
92-
93-
XCTAssertEqual(result?["view"] as? String, String(describing: view))
94-
XCTAssertEqual(result?["title"] as? String, "BUTTON TITLE")
95-
}
96-
97-
func testExtractDataFrom_ButtonWithout_Title() {
98-
let view = UIButton()
99-
100-
let result = Dynamic(SentryBreadcrumbTracker.self).extractDataFromView(view) as [String: Any?]?
101-
102-
XCTAssertEqual(result?["view"] as? String, String(describing: view))
103-
XCTAssertNil(result?["title"] as Any?)
104-
}
10563
#endif
10664

10765
}

0 commit comments

Comments
 (0)