Giter VIP home page Giter VIP logo

specleaks's Introduction

SpecLeaks

Version License Platform Build Status

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

Compatibility Notes:

Release Version: 0.1.8

  • Language version: Swift 5.0
  • iOS Deployment Target: 10.0
  • Travis CI running XCode version: 10.2

Cocoapods Installation

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

pod 'SpecLeaks'

Example Cocoapods 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.

Carthage Installation

Follow this guideline and to your Cartfile:

github "leandromperez/specleaks"

Note: don't forget to modify the framework search path from your testing target to include the folder that contains the compiled .framework files

Swift Package Manager Installation

In Xcode choose File | Swift Packages | Add package dependency and enter https://github.com/leandromperez/specleaks.

Example Carthage Project

There is a folder in the repo Carthage-Example that contains a project called Carthage-Tests configured to use Carthage.

  • Notice the following config entry in Build Settings: FRAMEWORK_SEARCH_PATHS = $(SRCROOT)/** $(SRCROOT)/../**

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

@bataleandro Leandro Perez

License

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

specleaks's People

Contributors

leandromperez avatar mstankiewiczzen avatar igorkulman avatar turekj avatar josueruiz7 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.