December 2018
Intermediate to advanced
414 pages
10h 19m
English
When writing unit tests, it's recommended to group together tests that are closely related to one other. We call a series of tests a suite, which can contain subsuites. Whole suites, subsuites, and individual tests can be run. These features makes the composite pattern very suitable for organizing the tests in suites, the suite itself being the composite.
First, we start with the base protocol, Testable. The only method it needs is the run method, to execute the contents of the test, and we'll use the errors thrown to indicate failure:
protocol Testable { func run() throws}
The following is the UnitTest class, which provides a simple wrapper around a name and a block that can be executed: ...
Read now
Unlock full access