Tutorial by Examples

When creating the project You should check "Include Unit Tests" in the project creation dialog. After creating the project If you missed checking that item while creating your project, you could always add test files later. To do so: 1- Go to your project settings in Xcode 2- Go to ...
To get started with unit testing, which will be done in the tests file and will be testing the View Controller and Storyboard, we should introduce these two files to the test file. Defining the View Controller Swift var viewController : ViewController! Introducing the Storyboard and initializi...
According to Apple: Test Methods A test method is an instance method of a test class that begins with the prefix test, takes no parameters, and returns void, for example, (void)testColorIsRed(). A test method exercises code in your project and, if that code does not produce the expected result, ...
Testing a specific method To test a specific method, click the square next to the method definition. Testing all methods To test all methods, click the square next to the class definition. See the testing result If there is a green check next to the definition, the test has succeeded. If the...
Classes, structs, enums and all their methods are internal by default. This means they can be only accessed from the same module. The test cases are in a different target an this means they are in a different module. To be able to access the method you want to test, you need to import the module to ...
View loading In a test for a view controller you want sometimes to trigger the execution of loadView() or viewDidLoad(). This can be done by accessing the view. Let's say you have view controller instance in your test called sut (system under test), then the code would look like this: XCTAssertNot...
import XCTest @testable import PersonApp class PersonTests: XCTestCase { func test_completeName() { let person = Person(firstName: "Josh", lastName: "Brown") XCTAssertEqual(person.completeName(), "Josh Brown") } } Now let's discuss wh...

Page 1 of 1