Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering iOS 18 Development

You're reading from   Mastering iOS 18 Development Take your iOS development experience to the next level with iOS, Xcode, Swift, and SwiftUI

Arrow left icon
Product type Paperback
Published in Nov 2024
Publisher Packt
ISBN-13 9781835468104
Length 418 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Avi Tsadok Avi Tsadok
Author Profile Icon Avi Tsadok
Avi Tsadok
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part 1: Getting Started with iOS 18 Development
2. Chapter 1: What’s New in iOS 18 FREE CHAPTER 3. Chapter 2: Simplifying Our Entities with SwiftData 4. Chapter 3: Understanding SwiftUI Observation 5. Chapter 4: Advanced Navigation with SwiftUI 6. Chapter 5: Enhancing iOS Applications with WidgetKit 7. Chapter 6: SwiftUI Animations and SF Symbols 8. Chapter 7: Improving Feature Exploration with TipKit 9. Chapter 8: Connecting and Fetching Data from the Network 10. Chapter 9: Creating Dynamic Graphs with Swift Charts 11. Part 2: Refine your iOS Development with Advanced Techniques
12. Chapter 10: Swift Macros 13. Chapter 11: Creating Pipelines with Combine 14. Chapter 12: Being Smart with Apple Intelligence and ML 15. Chapter 13: Exposing Your App to Siri with App Intents 16. Chapter 14: Improving the App Quality with Swift Testing 17. Chapter 15: Exploring Architectures for iOS 18. Index 19. Other Books You May Enjoy

Understanding the importance of testing

For many developers, testing is an unnecessary overhead they must deal with when writing code.

This way of thinking is somehow understandable. We’ve finished writing our code, built an application, and seen that everything runs as expected. Instead of moving to our next task, we need to change the target, adding a test function just so we can see again that it works fine. Why waste our time on it?

Also, in many cases, writing these test functions takes a lot of work. How can we test a SwiftUI view or a network call? What does it even mean?

These all summarize why testing is not a common practice, or at least not enough.

The root of this problem is how developers approach testing and writing code in general. Testing is more than checking whether our functions run as expected; it’s about code structure, separation of concerns, the writing process, working culture, and how we treat our day-to-day jobs.

Let’s look at the following function:

func canUserAddTask(to list: List, user: User) -> Bool {
    if list.isLocked {
        return false
    }
    if !list.allowedRoles.contains(user.role) {
        return false
    }
    return [.privateList,
      .publicList].contains(list.sharingAttribute)
}

This function checks whether a user can add a task to a specific list based on criteria, such as permissions, list type, and status. Now, imagine we need to ensure that this function works properly. How can we do that? Do we need to run our app in different states to see the results?

We all know that ensuring our code runs correctly is part of our development process. This is a classic example of how writing test cases and running an app in different states can ease our development process. We understand why testing is so important when adding future tasks such as refactoring and bug fixes.

Before we delve into Swift Testing, let’s understand the testing history in Apple platforms.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image