Latest0.1.1
Homepagehttps://github.com/leandromperez/specleaks
LicenseMIT
Platformsios 8.0
DependenciesQuick, Nimble
FrameworksUIKit, XCTest
Authors

Version
License
Platform

Create Unit Tests for Memory Leaks in Swift.

  • SpecLeaks allows you to create tests using Quick and Nimble.
  • Write readable tests for mem leaks easily with these Quick and Nimble extensions.

Quick and Nimble is a Unit Testing framework that allows you to write tests in a more humanly readable fashion.

What can you Test?

  • Test if an object is leaking when it is initialized.
  • Test if a ViewController is leaking when its view is loaded.
  • Test if a particular method is leaking

Installation

SpecLeaks is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'SpecLeaks'

Example Project

The example project contains a few Unit Tests that will let you understand how to use SpecLeaks.

To run the example project, clone the repo, and run pod install from the Example directory first.

Command+U to run the sample tests.

How to Write Tests

  1. Create a Spec
  2. Define a it("action") block
  3. Create a LeakTest passing a block that returns the object you want to test
  4. Write your expectations using toNot(leak()) or toNot(leakWhen())

Memory Leaks in initialization of plain Objects


class SomeObject {}

class SomeOjectTests: QuickSpec {
    override func spec() {
        describe("SomeObject") {
            describe("init") {
                it("must not leak"){
                    let someObject = LeakTest{
                        return SomeObject()
                    }

                    expect(someObject).toNot(leak())
                }
            }
        }
    }
}

Memory Leaks in viewDidLoad or init of a a UIViewController


class SomeViewController : UIViewController {}

class SomeViewControllerTests: QuickSpec {

    override func spec() {
        describe("SomeViewController"){
            describe("viewDidLoad") {
                let vc = LeakTest{
                    return SomeViewController()
                }
                it("must not leak"){
                    expect(vc).toNot(leak())
                }
            }
        }
    }
}

Memory Leaks when an action is called


class SomeObject{
    func doSomething(){

    }
}

class SomeOjectTests: QuickSpec {
    override func spec() {
        describe("SomeObject") {
            describe("doSomething") {
                it("must not leak"){

                    let someObject = LeakTest{
                        return SomeObject()
                    }

                    let doSomethingIsCalled : (SomeObject) -> ()  = {obj in
                         obj.doSomething()
                    }

                    expect(someObject).toNot(leakWhen(doSomethingIsCalled))
                }
            }
        }
    }
}

Author

[email protected], [email protected]

License

SpecLeaks is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SpecLeaks",
    "version": "0.1.1",
    "swift_version": "4.0",
    "summary": "Unit Tests Memory Leaks in Swift. Write readable tests for mem leaks easily with these Quick and Nimble extensions.",
    "description": "Quick and Nimble are tools that form a Unit Testing framework that allows you to write tests in a more humanly readable fashion. SpecLeaks is only a few additions to those tools. It lets you create unit tests to see if objects are leaking. You can test vanilla objects, view controllers, and see if an object or an action leaks",
    "homepage": "https://github.com/leandromperez/specleaks",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Leandro Perez": "[email protected]"
    },
    "source": {
        "git": "https://github.com/leandromperez/specleaks.git",
        "tag": "0.1.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "SpecLeaks/Classes/**/*",
    "frameworks": [
        "UIKit",
        "XCTest"
    ],
    "dependencies": {
        "Quick": [],
        "Nimble": []
    }
}

Pin It on Pinterest

Share This