Quick and Nimble

Çağatay Emekci
Mobile Development

--

Quick and Nimble are frameworks that are used in Unit tests in iOS. Quick is a testing framework and Nimble is a matching framework. They help us to write tests more easily and readably in addition to verifying how your programs behave. According to its documentation;

Quick is a behavior-driven development framework for Swift and Objective-C.

Nimble is a Matcher Framework for Swift and Objective-C

Their documentation is very explanatory to understand their framework features and that demonstrates what is the best practice to write Unit tests in iOS if you’re completely new to unit testing. Before you use this framework on your project, you should investigate their documentation. I would like to summarize some of these topics by following their documentation.

Effective Tests Using XCTest: Arrange, Act, and Assert

There are a lot of design patterns for unit testing. This topic explains how to write unit tests by following a simple pattern. Arrange, Act, Assert are good because they help you while structuring your testing code around particular-use cases.

Additionally, in this topic, there is also some information about naming test cases function. The test case name should be very clear for the reader of codes. Because when you are a part of the big development team, working in the same piece of code blog, some team members may want to use your test for understanding your code. In more detail;

Don’t Test Code, Instead Verify Behavior

You create many functions, classes, etc while developing a project. When writing the unit tests, you check whether their behavior has changed or not. If we try to explain this with an example, instead of checking data count in the database, you should check whether your data is in the database. In more detail; Blackbox test

Clearer Tests Using Nimble Assertions

You can use many assertions in the XCTest framework to compare two objects or check the object value. However, when XCTest assertions were used, there is no clear message when the code doesn’t work correctly. Therefore, it would be better to add an explanatory message to all assertions. If we use Nimble assertions instead of all these, we don’t need to add a message. Because Nimble assertions are already very readable. For more detail;

Organized Tests with Quick Examples and Example Groups

Quick uses a special syntax to define examples (it) and example groups (context, describe).

it: is used to define the specific expected result for the test.

context: is used to define the specific context of the action you’ll be testing.

describe: is used to define what action or behavior you’ll be testing.

beforeEach: similar to setup, it is run before each of the tests within this context/scope.

afterEach: similar to tear down, it is run after each of the tests within this context/scope.

describe("") {
beforeEach { }
afterEach { }
context("") {
it("") {
// ...
}
}
}

Testing OS X and iOS Applications

This title shows you how you can use Quick and Nimble to test your “uiviewcontrollers” in your project.

Testing with Mocks

You can use the all test doubles when you are using this framework. I have explained the test doubles on this link. This title shows you how you can use this framework with test doubles.

Conclusion

Quick and Nimble are easy to use and have the advantage that they are very descriptive of what you are testing. It allows us to describe the features of our code in a very readable and understandable way.

References

  1. Quick Framework
  2. Nimble Framework
  3. Raywenderlich

--

--

Çağatay Emekci
Mobile Development

iOS Application Developer, Opsgenie at Atlassian @CagatayEmekci