Skip to content

Commit 32f925f

Browse files
committed
update docs
1 parent 2aaaba1 commit 32f925f

File tree

8 files changed

+125
-10
lines changed

8 files changed

+125
-10
lines changed

Docs/XCUITests.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
# XCUITests
3+
4+
After the tests finish execution, the essential thing that we need is the simulator needs to stay alive.
5+
The problem with `XCUITests` is that after testing finish execution, it quit the simulator.
6+
7+
# Things I've tried:
8+
9+
1. Trying to find a way to preserve the running program after tests finish running
10+
11+
- I can't find any way to preserve the running program.
12+
13+
2. At the end of a test, run shell script to generate `memgraph` before the running program quit
14+
15+
For this idea, I put a breakpoint before the test finish execution. Then we can custom that breakpoint to execute a shell script command.
16+
However, when running on CI, we will execute test using script, not from Xcode. So, using breakpoint to execute shell script will not work for CI
17+
18+
=> Only work on Xcode
19+
20+
3. From Xcode13, Apple provide `-enablePerformanceTestsDiagnostics` to generate memgraph after a test finish executing.
21+
22+
```bash
23+
xcodebuild test -project MemoryLeaksCheck.xcodeproj \
24+
-scheme LeaksCheckerUITests \
25+
-destination platform=iOS,name="Tuan iPhone" \
26+
-enablePerformanceTestsDiagnostics YES
27+
```
28+
29+
> Note: In the scheme configuration, open `Options` under `Test`, unselect "Delete if test succeeds" for Attachments.
30+
31+
<img src=../resources/xcuitests.png width=800/>
32+
33+
However, **this only works for real device, not for simulator.**
34+
35+
Based on [Apple docs](https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes)
36+
37+
> xcodebuild has a new option -enablePerformanceTestsDiagnostics YES that collects diagnostics for Performance XCTests. The option collects a ktrace file for non-XCTMemoryMetrics, and a series of memory graphs for XCTMemoryMetrics. xcodebuild attaches diagnostics to the generated xcresult bundle. **Note that memory graph collection isn’t available in simulated devices. (64495534)**
38+
39+
=> Only work on local with real device, doesn't work on CI
40+
41+
# Conclusion
42+
43+
XCUITests is not appropriate for this approach. (for now)

LeaksCheckerUITests/LeaksCheckerUITests.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ final class LeaksCheckerUITests: XCTestCase {
1717
super.tearDown()
1818
}
1919

20-
func testExample() throws {
20+
/// This is a solution to generate memgraph using breakpoint.
21+
/// => this solution only work when you running test using Xcode.
22+
func testExample_usingBreakpointToGenrateMemgraph() throws {
2123

2224
// UI tests must launch the application that they test.
2325
app = XCUIApplication(bundleIdentifier: "Hoang-Anh-Tuan.MemoryLeaksCheck")
@@ -41,5 +43,31 @@ final class LeaksCheckerUITests: XCTestCase {
4143
/// - Parameters: The parameters is passed in the shell script is the program name, which is our app name. For this project, the app name is *MemoryLeaksCheck*.
4244
debugPrint("Start checking for leaks... 🔎")
4345
}
46+
47+
/// This test will generate memgraph via command line. However, it only works on physical device, not simulator.
48+
/// For more info, please read README.
49+
func testExample() throws {
50+
let app = XCUIApplication()
51+
let options = XCTMeasureOptions()
52+
53+
measure(
54+
metrics: [XCTMemoryMetric(application: app)],
55+
options: options
56+
) {
57+
app.launch()
58+
startMeasuring()
59+
60+
app.staticTexts["Abandoned Memory Example"].tap()
61+
app.buttons["Scenarios"].tap()
4462

63+
app.staticTexts["Leaks Memory Example"].tap()
64+
65+
let simulateLogoutThenLoginActionButton = app.buttons["Simulate Logout then Login Action"]
66+
simulateLogoutThenLoginActionButton.tap()
67+
simulateLogoutThenLoginActionButton.tap()
68+
simulateLogoutThenLoginActionButton.tap()
69+
simulateLogoutThenLoginActionButton.tap()
70+
}
71+
}
72+
4573
}

MemoryLeaksCheck.xcodeproj/project.pbxproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
};
167167
4CBC59372AC3299B00D83CA5 = {
168168
CreatedOnToolsVersion = 14.2;
169+
TestTargetID = 4C28E3C92ABEDFFB0004394E;
169170
};
170171
};
171172
};
@@ -382,7 +383,7 @@
382383
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
383384
CODE_SIGN_STYLE = Automatic;
384385
CURRENT_PROJECT_VERSION = 1;
385-
DEVELOPMENT_TEAM = RCQA85T6C2;
386+
DEVELOPMENT_TEAM = 98D3824HFQ;
386387
GENERATE_INFOPLIST_FILE = YES;
387388
INFOPLIST_FILE = MemoryLeaksCheck/Info.plist;
388389
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
@@ -414,7 +415,7 @@
414415
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
415416
CODE_SIGN_STYLE = Automatic;
416417
CURRENT_PROJECT_VERSION = 1;
417-
DEVELOPMENT_TEAM = RCQA85T6C2;
418+
DEVELOPMENT_TEAM = 98D3824HFQ;
418419
GENERATE_INFOPLIST_FILE = YES;
419420
INFOPLIST_FILE = MemoryLeaksCheck/Info.plist;
420421
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
@@ -444,7 +445,7 @@
444445
buildSettings = {
445446
CODE_SIGN_STYLE = Automatic;
446447
CURRENT_PROJECT_VERSION = 1;
447-
DEVELOPMENT_TEAM = RCQA85T6C2;
448+
DEVELOPMENT_TEAM = 98D3824HFQ;
448449
GENERATE_INFOPLIST_FILE = YES;
449450
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
450451
MARKETING_VERSION = 1.0;
@@ -457,6 +458,7 @@
457458
SWIFT_EMIT_LOC_STRINGS = NO;
458459
SWIFT_VERSION = 5.0;
459460
TARGETED_DEVICE_FAMILY = 1;
461+
TEST_TARGET_NAME = MemoryLeaksCheck;
460462
};
461463
name = Debug;
462464
};
@@ -465,7 +467,7 @@
465467
buildSettings = {
466468
CODE_SIGN_STYLE = Automatic;
467469
CURRENT_PROJECT_VERSION = 1;
468-
DEVELOPMENT_TEAM = RCQA85T6C2;
470+
DEVELOPMENT_TEAM = 98D3824HFQ;
469471
GENERATE_INFOPLIST_FILE = YES;
470472
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
471473
MARKETING_VERSION = 1.0;
@@ -478,6 +480,7 @@
478480
SWIFT_EMIT_LOC_STRINGS = NO;
479481
SWIFT_VERSION = 5.0;
480482
TARGETED_DEVICE_FAMILY = 1;
483+
TEST_TARGET_NAME = MemoryLeaksCheck;
481484
};
482485
name = Release;
483486
};

MemoryLeaksCheck.xcodeproj/xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
99
<BreakpointContent
1010
uuid = "36593BB7-BE9C-457C-8CE7-A83C591BB7A4"
11-
shouldBeEnabled = "Yes"
11+
shouldBeEnabled = "No"
1212
nameForDebugger = "CheckingForLeaks"
1313
ignoreCount = "0"
1414
continueAfterRunningActions = "No"
1515
filePath = "LeaksCheckerUITests/LeaksCheckerUITests.swift"
1616
startingColumnNumber = "9223372036854775807"
1717
endingColumnNumber = "9223372036854775807"
18-
startingLineNumber = "42"
19-
endingLineNumber = "42"
20-
landmarkName = "testExample()"
18+
startingLineNumber = "44"
19+
endingLineNumber = "44"
20+
landmarkName = "testExample_usingBreakpointToGenrateMemgraph()"
2121
landmarkType = "7">
2222
<Actions>
2323
<BreakpointActionProxy

MemoryLeaksCheck.xcodeproj/xcshareddata/xcschemes/LeaksCheckerUITests.xcscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
buildConfiguration = "Debug"
1111
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
1212
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13-
shouldUseLaunchSchemeArgsEnv = "YES">
13+
shouldUseLaunchSchemeArgsEnv = "YES"
14+
userAttachmentLifetime = "keepAlways">
1415
<AdditionalOptions>
1516
<AdditionalOption
1617
key = "MallocStackLogging"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>LeaksCheckerUITests.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
<key>MemoryLeaksCheck.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>1</integer>
16+
</dict>
17+
<key>SnapKitPlayground (Playground) 1.xcscheme</key>
18+
<dict>
19+
<key>isShown</key>
20+
<false/>
21+
<key>orderHint</key>
22+
<integer>3</integer>
23+
</dict>
24+
<key>SnapKitPlayground (Playground) 2.xcscheme</key>
25+
<dict>
26+
<key>isShown</key>
27+
<false/>
28+
<key>orderHint</key>
29+
<integer>4</integer>
30+
</dict>
31+
<key>SnapKitPlayground (Playground).xcscheme</key>
32+
<dict>
33+
<key>isShown</key>
34+
<false/>
35+
<key>orderHint</key>
36+
<integer>2</integer>
37+
</dict>
38+
</dict>
39+
</dict>
40+
</plist>

resources/xcuitests.png

58 KB
Loading

0 commit comments

Comments
 (0)