{"id":13462722,"url":"https://github.com/zalando/SwiftMonkey","last_synced_at":"2025-03-25T05:32:14.039Z","repository":{"id":13446568,"uuid":"74459010","full_name":"zalando/SwiftMonkey","owner":"zalando","description":"A framework for doing randomised UI testing of iOS apps","archived":true,"fork":false,"pushed_at":"2022-10-21T12:50:00.000Z","size":372,"stargazers_count":1949,"open_issues_count":27,"forks_count":175,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-03-19T12:03:38.201Z","etag":null,"topics":["testing"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zalando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-22T09:58:47.000Z","updated_at":"2025-02-05T09:36:10.000Z","dependencies_parsed_at":"2022-11-29T13:19:45.886Z","dependency_job_id":null,"html_url":"https://github.com/zalando/SwiftMonkey","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando%2FSwiftMonkey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando%2FSwiftMonkey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando%2FSwiftMonkey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando%2FSwiftMonkey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zalando","download_url":"https://codeload.github.com/zalando/SwiftMonkey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245407577,"owners_count":20610227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["testing"],"created_at":"2024-07-31T13:00:19.585Z","updated_at":"2025-03-25T05:32:13.619Z","avatar_url":"https://github.com/zalando.png","language":"Swift","funding_links":[],"categories":["[Archived] iOS Apps (Search Results)","Swift","功能测试","Test"],"sub_categories":["App性能测试"],"readme":"# SwiftMonkey\n\nThis project is a framework for generating randomised user input\nin iOS apps. This kind of monkey testing is useful for\nstress-testing apps and finding rare crashes.\n\nIt also contains a related framework called SwiftMonkeyPaws, which\nprovides visualisation of the generated events. This greatly\nincreases the usefulness of your randomised testing, as you can\nsee what touches caused any crash you may encounter.\n\n## Why Use SwiftMonkey?\n\n- When testing your UI, it's very easy to think about how to test\n  how things *should* work, but do you struggle to figure out\n  what kind of thing might *not* work?\n- Ever showed your app to someone who proceeded to bang away at the\n  screen and immediately crashed it by doing something you had never\n  thought of?\n- Do you want to feel a bit more confident about your app's stability?\n- Do you have rare crashes that you just can't reproduce?\n- Do you have memory leaks that take a long time to manifest\n  themselves, and require lots of UI actions?\n\nRandomised testing will help you with all of these!\n\nSwiftMonkey is inspired by and has similar goals to\n[UI AutoMonkey][], but is integrated into the Xcode UI testing\nframework, providing better opportunities to debug.\n\nAlso, it is fun to look at:\n\n\u003cimg src=\"https://thumbs.gfycat.com/IndolentTallFoxterrier-size_restricted.gif\" height=\"480\"\u003e\n\n## Quick Start\n\nTo see for yourself how this framework works, just grab the code\nand open `SwiftMonkeyExample/SwiftMonkeyExample.xcodeproj`. Then press `Cmd-U` to run the UI test.\n\n## Installation\n\nAs a high-level overview, add `SwiftMonkey.framework` to your\nUI test target. Then add a test that creates a `Monkey`\nobject and uses it to generate events.\n\nOptionally, you also add the `SwiftMonkeyPaws.framework` to your\nmain app, and create a `MonkeyPaws` object to enable visualisation.\nYou probably only want to do this for debug builds, or when a\nspecific command line flag is used.\n\n### Requirements\n\nSwiftMonkey uses Swift 4.0. It has no dependencies other than\niOS itself (8.0 and up should work). SwiftMonkeyPaws doesn't\nhave any dependencies, either; you can even use on its own,\nwithout SwiftMonkey.\n\n### CocoaPods\n\nYou can install the frameworks using [CocoaPods][]. Assuming\nthat you've named your main app and test targets \"App\" and \"Tests\", you\ncan use something like this in your `Podfile`:\n\n````ruby\ntarget 'App' do\n    pod 'SwiftMonkeyPaws', '~\u003e 2.1.0'\nend\n\ntarget 'Tests' do\n    pod 'SwiftMonkey', '~\u003e 2.1.0'\nend\n````\n\n### Manual Installation\n\nCopy the `SwiftMonkey` and `SwiftMonkeyPaws` folders into your\nproject. Next, drag the `xcodeproj` files into your project.\n\nThen, for SwiftMonkey, add `SwiftMonkey.framework` as a\ndependency for your test target, and add a Copy Files build\nphase to copy it into `Frameworks`.\n\nFor SwiftMonkeyPaws, adding `SwiftMonkeyPaws.framework` to the\nEmbedded Binaries section of your app target is enough.\n\n(You can also just directly link the Swift files, if you do not\nwant to use frameworks.)\n\n### Swift Package Manager\n\nAs of this writing, the Swift Package Manager doesn't support\niOS projects. SPM package files have experimentally been created,\nbut obviously don't really work yet.\n\n## Usage\n\n### SwiftMonkey\n\nTo do monkey testing, `import SwiftMonkey`, then create a new\ntest case that uses the `Monkey` object to configure and run\nthe input event generation. Here is a simple example:\n\n````swift\nfunc testMonkey() {\n        let application = XCUIApplication()\n\n        // Initialise the monkey tester with the current device\n        // frame. Giving an explicit seed will make it generate\n        // the same sequence of events on each run, and leaving it\n        // out will generate a new sequence on each run.\n        let monkey = Monkey(frame: application.frame)\n        //let monkey = Monkey(seed: 123, frame: application.frame)\n\n        // Add actions for the monkey to perform. We just use a\n        // default set of actions for this, which is usually enough.\n        // Use either one of these but maybe not both.\n\n        // XCTest private actions seem to work better at the moment.\n        // before Xcode 10.1, you can use\n        // monkey.addDefaultXCTestPrivateActions()\n\n        // after Xcode 10.1 We can only use public API\n        monkey.addDefaultXCTestPublicActions()\n\n        // UIAutomation actions seem to work only on the simulator.\n        //monkey.addDefaultUIAutomationActions()\n\n        // Occasionally, use the regular XCTest functionality\n        // to check if an alert is shown, and click a random\n        // button on it.\n        monkey.addXCTestTapAlertAction(interval: 100, application: application)\n\n        // Run the monkey test indefinitely.\n        monkey.monkeyAround()\n}\n````\n\nThe `Monkey` object allows you not only to add the built-in\nevent generators, but also any block of your\nown to be executed either randomly or at set intervals. In\nthese blocks you can do whatever you want, including (but not\nonly) generate more input events.\n\nDocumentation for this is limited at the moment, so please\nrefer to `Monkey.swift` and its extensions for examples of\nhow to use the more advanced functionality if you need it.\n\n### SwiftMonkeyPaws\n\nThe simplest way to enable the visualisation in your app is to\nfirst `import SwiftMonkeyPaws`, then do the following somewhere\nearly on in your program execution:\n\n````swift\nvar paws: MonkeyPaws?\n\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n    if CommandLine.arguments.contains(\"--MonkeyPaws\") {\n        paws = MonkeyPaws(view: window!)\n    }\n    return true\n}\n````\n\n(This example uses `application(_, didFinishLaunchingWithOptions)`,\nbut any time after you have a UIWindow will do. It also only\ninstatiates the visualisation if a certain command line flag\nis passed, so that it can be enabled only for test runs.)\n\nUsing command line flags, If you want to enable MonkeyPaws on your\ntest case file you can add the following on yout testMonkey function:\n\n````swift\n  let application = XCUIApplication()\n  application.launchArguments = [\"--MonkeyPaws\"]\n````\n\nThis call will swizzle some methods in UIApplication to capture\nUIEvents. If you would rather not do this, or if you already have\na source of UIEvents, you can pass the following option to `init`\nto disable swizzling:\n\n````swift\npaws = MonkeyPaws(view: window!, tapUIApplication: false)\n````\n\nThen you can pass in events with the following call:\n\n````swift\npaws?.append(event: event) // event is UIEvent\n````\n\n## Contributing\n\nFeel free to file issues and send pull requests for this\nproject! It is very new and not overly organised yet, so be\nbold and go ahead. We will sort out the details as we go along.\n\nCode style is currently just four-space identation and regular\nApple Swift formatting.\n\nAlso, we have adopted the Contributor Covenant as the code\nof conduct for this project:\n\n\u003chttp://contributor-covenant.org/version/1/4/\u003e\n\n### Thanks to\n\n* The Zalando Open Source Guild for helping get this project\n  off the ground.\n* João Nunes for help with documentation.\n* Jakub Mucha for bugfixing.\n\n## TODO\n\n### SwiftMonkey\n\n- Write more documentation.\n- Add more input event actions.\n- Add randomised testing using public XCTest APIs instead of private ones.\n  - Find clickable view and click them directly instead of\n    clicking random locations, to compensate for the slow\n    event generation.\n- Fix swipe actions to avoid pulling out the top and bottom panels. (This\n  can cause the monkey to escape from your app, which can be problematic!)\n- Generally, find a quick way to see if the monkey manages to leave the\n  application.\n- Find out how to do device rotations using XCTest private API.\n- Find out why UIAutomation actions do not work on device, but only on the\n  simulator.\n- Investigate other methods of generating input events that do not rely\n  on private APIs.\n- Once Swift Package Manager has iOS support, update project\n  to support it properly.\n\n### SwiftMonkeyPaws\n\n- Add more customisability for the visualisation.\n\n### SwiftMonkeyExample\n\n- Add more UI elements, views and controls to make the example\n  look more interesting.\n- Maybe add some actual crashes that the monkey testing can find?\n\n## Contact\n\nThis software was originally written by Dag Ågren\n(dag.agren@zalando.fi) for Zalando SE. This email address serves\nas the main contact address for this project.\n\nBug reports and feature requests are more likely to be addressed\nif posted as issues here on GitHub.\n\n## License\n\nThe MIT License (MIT) Copyright © 2016 Zalando SE, https://tech.zalando.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[CocoaPods]: https://cocoapods.org/\n[UI AutoMonkey]: https://github.com/jonathanpenn/ui-auto-monkey\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalando%2FSwiftMonkey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzalando%2FSwiftMonkey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalando%2FSwiftMonkey/lists"}