A simple package that enables you to easily integrate the Memory leaks check to your CI workflow
? CILeaksDetector
This is a simple package that enables you to easily integrate the Memory leaks check to your CI workflow.
Getting started
Usage
Just need to follow these simple steps:
-
Copy
Dangerfile.leaksReport
to your project. This contains the logic to get the leaks message and post to your Pull request. You can custom this Dangerfile. Learn more aboutDanger
here -
Create a maestro flow to run simulate the flow in your app. Learn more about
Maestro
here -
In your ci workflow, just call:
leaksdetector -processName $YOUR_APP_NAME -e $SUPPORTED_TESTING_FRAMEWORKS -d $PATH_TO_DANGER_FILE
Current support testing frameworks
How it works
-
Use Maestro to simulate the UI flow in your app.
-
Generate
memgraph
usingleaks
tool provided by Apple. Find more aboutleaks
tool andmemgraph
here -
Use
leaksdetector
program to proceed thememgraph
file. If any leaks founded, it will use Danger to post a message to your PR/slack, …
Why I used Maestro?
-
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.
-
I’ve tried to used XCUItest, which is really promissing. Based on this WWDC video 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 and developer.apple. If you have any ideas, feel free to reply on the threads
How to support your testing frameworks
If you’re using another UI testing framework which also support preserve the execution of the program after finish testing, you can create another PR to update the leaksdetector
.
It’s easy to do that, just need to follow these steps:
- Open
Executor.swift
, create a new instance of your testing frameworks. Your new instance needs to conform toExecutor
protocol.
struct XCUITestExecutor: Executor {
func simulateUI() throws {
// Custom logic to start simulating UI
}
func generateMemgraph(for processName: String) throws {
// Custom logic to start generating memgraph for a `processName`
}
func getMemgraphPath() -> String {
// return the path to the generated memgraph
}
}
-
Open
ExecutorFactory.swift
, define your new UI testing frameworks to theExecutorType
, and add logic to generate it in thecreateExecutor
func. -
Add new
@Option
to the executable program if need
Result
Publication
I’ve published an article about this on Medium. You can take a look at here