Unit Tests

There are different ways to test that the UIViewController has been successfully pushed onto the navigation stack and in this tutorial, I will cover a few of them. For this tutorial, I have created a simple project with two view controllers on the Main.storyboard. The very first view controller has a button. When the button…

Read More Test View Controller Push to Navigation Controller

There are a few different ways to Unit test code that throws an Error in Swift and my preferred way is to use the XCTAssertThrowError and XCTAssertNoThrows. I will also share with you how to use the traditional way of handling an error with the do-try-catch. Error To Be Thrown Let’s assume that we have…

Read More Unit Testing Code That Throws Error in Swift

There are different ways to load UIViewController in a Unit Test and in this tutorial you will learn three of them. Loading UIViewController from Main.storyboard, Loading UIViewController from XIB, Loading UIViewController that is not on the Main.storyboard and does have an interface XIB file. This is a type of UIViewController that creates views programmatically. Loading…

Read More Ways to Load UIViewController in a Unit Test

There are times when we need our UI Test code to pass some information to our mobile app, not by typing it into a Text Field or a Text View but by sending it as a command-line argument or as a launch environment property. To pass a command-line launch argument or an environment key-value pair…

Read More UI Testing. Launch Arguments & Launch Environment

When writing unit tests, developers try to follow the F.I.R.S.T principle as much as possible. F.I.R.S.T is a combination of multiple principles. Let’s learn what these are. Fast The first letter in the F.I.R.S.T principle stands for – Fast. Unit tests are small pieces of code that perform one, specific task. Because unit tests are…

Read More The F.I.R.S.T. Principle in Unit Testing

The addTeardownBlock(_:) runs right after the test method ends and before the instance’s tearDownWithError() method is called. Below is an example of a TestCase class that does not test anything and only demonstrates the order in which the setUp() and tearDown() methods are called. When will the addTeardownBlock(_:) run? The addTeardownBlock will run after the test method is…

Read More addTeardownBlock Example in XCTestCase

In this XCTest tutorial, you will learn how to write a unit test that will test if UIButton is connected to @IBOutlet and has @IBAction assigned. For this tutorial, I will create a Single View application project. I will use the default View Controller that XCode creates for all new projects and I will position…

Read More XCTest. Test if UIButton is Connected And Has Action