diff --git a/Docs/XCUITests.md b/Docs/XCUITests.md
new file mode 100644
index 0000000..88b6e38
--- /dev/null
+++ b/Docs/XCUITests.md
@@ -0,0 +1,43 @@
+
+# XCUITests
+
+After the tests finish execution, the essential thing that we need is the simulator needs to stay alive.
+The problem with `XCUITests` is that after testing finish execution, it quit the simulator.
+
+# Things I've tried:
+
+1. Trying to find a way to preserve the running program after tests finish running
+
+- I can't find any way to preserve the running program.
+
+2. At the end of a test, run shell script to generate `memgraph` before the running program quit
+
+For this idea, I put a breakpoint before the test finish execution. Then we can custom that breakpoint to execute a shell script command.
+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
+
+=> Only work on Xcode
+
+3. From Xcode13, Apple provide `-enablePerformanceTestsDiagnostics` to generate memgraph after a test finish executing.
+
+```bash
+ xcodebuild test -project MemoryLeaksCheck.xcodeproj \
+ -scheme LeaksCheckerUITests \
+ -destination platform=iOS,name="Tuan iPhone" \
+ -enablePerformanceTestsDiagnostics YES
+```
+
+> Note: In the scheme configuration, open `Options` under `Test`, unselect "Delete if test succeeds" for Attachments.
+
+
+
+However, **this only works for real device, not for simulator.**
+
+Based on [Apple docs](https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes)
+
+> 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)**
+
+=> Only work on local with real device, doesn't work on CI
+
+# Conclusion
+
+XCUITests is not appropriate for this approach. (for now)
diff --git a/LeaksCheckerUITests/LeaksCheckerUITests.swift b/LeaksCheckerUITests/LeaksCheckerUITests.swift
index 80cffe8..19239f4 100644
--- a/LeaksCheckerUITests/LeaksCheckerUITests.swift
+++ b/LeaksCheckerUITests/LeaksCheckerUITests.swift
@@ -17,7 +17,9 @@ final class LeaksCheckerUITests: XCTestCase {
super.tearDown()
}
- func testExample() throws {
+ /// This is a solution to generate memgraph using breakpoint.
+ /// => this solution only work when you running test using Xcode.
+ func testExample_usingBreakpointToGenrateMemgraph() throws {
// UI tests must launch the application that they test.
app = XCUIApplication(bundleIdentifier: "Hoang-Anh-Tuan.MemoryLeaksCheck")
@@ -41,5 +43,31 @@ final class LeaksCheckerUITests: XCTestCase {
/// - 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*.
debugPrint("Start checking for leaks... π")
}
+
+ /// This test will generate memgraph via command line. However, it only works on physical device, not simulator.
+ /// For more info, please read README.
+ func testExample() throws {
+ let app = XCUIApplication()
+ let options = XCTMeasureOptions()
+
+ measure(
+ metrics: [XCTMemoryMetric(application: app)],
+ options: options
+ ) {
+ app.launch()
+ startMeasuring()
+
+ app.staticTexts["Abandoned Memory Example"].tap()
+ app.buttons["Scenarios"].tap()
+ app.staticTexts["Leaks Memory Example"].tap()
+
+ let simulateLogoutThenLoginActionButton = app.buttons["Simulate Logout then Login Action"]
+ simulateLogoutThenLoginActionButton.tap()
+ simulateLogoutThenLoginActionButton.tap()
+ simulateLogoutThenLoginActionButton.tap()
+ simulateLogoutThenLoginActionButton.tap()
+ }
+ }
+
}
diff --git a/MemoryLeaksCheck.xcodeproj/project.pbxproj b/MemoryLeaksCheck.xcodeproj/project.pbxproj
index 880e558..ea52167 100644
--- a/MemoryLeaksCheck.xcodeproj/project.pbxproj
+++ b/MemoryLeaksCheck.xcodeproj/project.pbxproj
@@ -166,6 +166,7 @@
};
4CBC59372AC3299B00D83CA5 = {
CreatedOnToolsVersion = 14.2;
+ TestTargetID = 4C28E3C92ABEDFFB0004394E;
};
};
};
@@ -382,7 +383,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
- DEVELOPMENT_TEAM = RCQA85T6C2;
+ DEVELOPMENT_TEAM = 98D3824HFQ;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = MemoryLeaksCheck/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
@@ -414,7 +415,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
- DEVELOPMENT_TEAM = RCQA85T6C2;
+ DEVELOPMENT_TEAM = 98D3824HFQ;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = MemoryLeaksCheck/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
@@ -444,7 +445,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
- DEVELOPMENT_TEAM = RCQA85T6C2;
+ DEVELOPMENT_TEAM = 98D3824HFQ;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
@@ -457,6 +458,7 @@
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
+ TEST_TARGET_NAME = MemoryLeaksCheck;
};
name = Debug;
};
@@ -465,7 +467,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
- DEVELOPMENT_TEAM = RCQA85T6C2;
+ DEVELOPMENT_TEAM = 98D3824HFQ;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0;
@@ -478,6 +480,7 @@
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
+ TEST_TARGET_NAME = MemoryLeaksCheck;
};
name = Release;
};
diff --git a/MemoryLeaksCheck.xcodeproj/project.xcworkspace/xcuserdata/tuanhoang.xcuserdatad/UserInterfaceState.xcuserstate b/MemoryLeaksCheck.xcodeproj/project.xcworkspace/xcuserdata/tuanhoang.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..6f1b1da
Binary files /dev/null and b/MemoryLeaksCheck.xcodeproj/project.xcworkspace/xcuserdata/tuanhoang.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/MemoryLeaksCheck.xcodeproj/xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist b/MemoryLeaksCheck.xcodeproj/xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist
index e2b1154..a2bdc4f 100644
--- a/MemoryLeaksCheck.xcodeproj/xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/MemoryLeaksCheck.xcodeproj/xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -8,16 +8,16 @@
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ userAttachmentLifetime = "keepAlways">
+
+
+
+ SchemeUserState
+
+ LeaksCheckerUITests.xcscheme_^#shared#^_
+
+ orderHint
+ 0
+
+ MemoryLeaksCheck.xcscheme_^#shared#^_
+
+ orderHint
+ 1
+
+ SnapKitPlayground (Playground) 1.xcscheme
+
+ isShown
+
+ orderHint
+ 3
+
+ SnapKitPlayground (Playground) 2.xcscheme
+
+ isShown
+
+ orderHint
+ 4
+
+ SnapKitPlayground (Playground).xcscheme
+
+ isShown
+
+ orderHint
+ 2
+
+
+
+
diff --git a/README.md b/README.md
index d92ac18..6af59fc 100644
--- a/README.md
+++ b/README.md
@@ -23,10 +23,10 @@ Learn more about `Maestro` [here](https://maestro.mobile.dev/)
leaksdetector -processName $YOUR_APP_NAME -e $SUPPORTED_TESTING_FRAMEWORKS -d $PATH_TO_DANGER_FILE
```
-## Current support testing frameworks
+## Current testing frameworks
- [Maestro](https://maestro.mobile.dev/) β
-- [XCUITest](https://developer.apple.com/documentation/xctest) (In progress βοΈ)
+- [XCUITest](https://developer.apple.com/documentation/xctest) (XCUITest is not supported. Read more [here](./Docs/XCUITests.md)) β
## How it works
@@ -40,11 +40,7 @@ Find more about `leaks` tool and `memgraph` [here](https://developer.apple.com/v
## Why I used Maestro?
1. I need a testing tool which doesn't kill the program after the testing finished execution. And Maestro support that. Also Maestro is very easy to integrate & use.
-2. I've tried to used XCUItest, which is really promissing. Based on this [WWDC video](https://developer.apple.com/videos/play/wwdc2021/10180/) from Apple, XCUITest even *allows us to capture the stacktrace where leaks occur & generate a memgraph*. However, I've tried to follow the video but Xcode didn't generate any memgraph.
-
- => I'm working on this.
-
- I've posted some questions on [swiftforum](https://forums.swift.org/t/xctest-doesnt-generate-memgraph-file-after-ui-test-finish-execution/67982) and [developer.apple](https://developer.apple.com/forums/thread/738659). If you have any ideas, feel free to reply on the threads
+2. XCUITest can not preserve running program after test execution. Read more at [here](./Docs/XCUITests.md)
## How to support your testing frameworks
diff --git a/resources/xcuitests.png b/resources/xcuitests.png
new file mode 100644
index 0000000..ab351c3
Binary files /dev/null and b/resources/xcuitests.png differ