Coder Social home page Coder Social logo

xctest-resettable's Introduction

🪶 xctest-resettable

CI

A framework to help keep your unit tests lightweight.

Motivation

In large projects with a big test suite it's easy to see how the memory consumption keeps increasing while running the tests. This is due to the XCTestCase workflow. When an XCTestCase class runs its tests a new test case is instantiated, one for each test method it has and if it's not released, a new instance of the test subject will keep being added to memory. These objects should be released when the test is finished and the proper way to do it is in the tearDown() method the test case provides. The solution would look like the following:

var sut: SUT! = SUT()

override func tearDown() {
    sut = nil
    super.tearDown()
}

This framework, based on this principle, implements additional logic so that this process is done under the hood by simply adding a property wrapper to your test objects.

Usage

The property wrapper that enables the release of your test objects is @Resettable and it works under a ResettableTestCase subclass. These are the different ways you can use the @Resettable property wrapper:

Lazy init

@Resettable var sut: SUT!

override func setUp() {
    super.setUp()
    sut = SUT()
}

Init with reset method

It's also possible to add a method to the property wrapper that will be executed in the tearDown() method right before releasing the object.

class SUT {
    func reset() { ... }
}

@Resettable(onReset: SUT.reset)
var sut: SUT! = SUT()

Note: The reset method must be declared within the test object.

The code above will be translated to the following using tearDown():

override func tearDown() {
    sut.reset()
    sut = nil
    super.tearDown()
}

xctest-resettable's People

Contributors

pbalduz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.