Menu
  • Home
  • About Me
SwiftyJimmy
Software development with Swift

How to do unit testing in Swift

Why should we do unit testing with Swift? Unit testing is a crucial part of every SW project. It’s main purpose is to prevent errors from shipping. Unit tests also works as a safety net for you program. If you have written a big piece of code few months ago, and now you need to refactor that, unit tests are your best friend. Unit tests make sure you won’t break anything. If you have written test for all use cases and corner cases, you can be sure even after the refactoring that the application works as intended in the first place.

Unit tests also document the code. Usually it helps a lot to check the unit tests for a struct or class to what it is all about.

I’ll collect the best techniques and ideas about unit testing with swift under this category. Some of the posts are small and on a very specific topic mock network layer for unit testing with Swift. But others, for example how to unit test ViewModel in swift, are complete tutorials about a bigger topic.

I hope you’ll find the topics helpful, and if there is something you’ll like to add or ask about, please do!

Unit testing RxSwift application with XCTest framework

Unit testing RxSwift application with XCTest framework

  • Posted on October 6, 2018
  • /Under How to do unit testing in Swift, How to use RxSwift with MVVM
Unit testing RxSwift app is the topic I want to talk about today. This is the last part of the series How to use RxSwift with MVVM, where we have learned to use RxSwift by implementing the Friends application. The only remaining thing is to unit test the application. Unit…continue reading →
Mock UIApplication for unit tests in Swift

Mock UIApplication for unit tests in Swift

  • Posted on November 13, 2017
  • /Under How to do unit testing in Swift
This time I wanted to talk about how to mock UIApplication, or any other library for unit testing. When you are writing unit tests you want to be in control. With a specific input the output must always be what you expect. That is the main reason why you shouldn't…continue reading →
Mock network layer for unit testing in Swift

Mock network layer for unit testing in Swift

  • Posted on October 1, 2017
  • /Under How to do unit testing in Swift
Mock network layer for unit testing is an interesting topic. It will help you to make your unit tests more robust. Many times the models, wrappers and modules that you write depend on a network requests. For different responses you'll need different behaviour. How will the class recover from a…continue reading →
How to unit test ViewModel in Swift

How to unit test ViewModel in Swift

  • Posted on May 9, 2017
  • /Under How to do unit testing in Swift, Model-View-ViewModel with swift
In this blog post, we are going to unit test the MVVM Friends mobile application. We did go through the application implementation in the previous three-part blog post series MVVM with Swift application, and now is the time to write unit tests for the application. There are few topics that will be covered today: Unit…continue reading →
Search
Categories
  • How to do unit testing in Swift
  • How to use RxSwift with MVVM
  • Model-View-ViewModel with swift
  • Server-side swift examples
  • Uncategorized
Recent Posts
  • Server-side Swift with Vapor 3 – backend set up March 26, 2019
  • Unit testing RxSwift application with XCTest framework October 6, 2018
  • Network request with RxSwift example September 23, 2018
  • How to use RxSwift with MVVM pattern part 2 August 31, 2018
  • How to use RxSwift with MVVM pattern July 18, 2018
Subscribe to a montly news letter
Recommended Books
  • The Pragmatic Programmer
  • Domain Driven design
  • iOS 11 Programming Fundamentals with Swift
  • Swift Programming: The Big Nerd Ranch Guide