Testing the Sandwiches SwiftUI WWDC Code

Without the Hot Dogs References

Steven Curtis
2 min readMay 25, 2023
Photo by Ball Park Brand on Unsplash

I’ve previously written an article where I recreated the code from a Video from WWDC.

I’m taking a view about the necessity of viewModels when using SwiftUI, and part of that investigation is around testing.

Can I write even simple tests for that code, and get them working? Let’s take a look.

Before we begin

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 12.0, and Swift 5.3

Terminology:

SwiftUI: A simple way to build user interfaces across Apple platforms

Prerequisites:

  • You will be expected to be aware how to make a SwiftUI project

The experiment

if DEBUG macro

The setup I’ve taken the code from that old article I knocked together. One thing that was fine was skipping the #if DEBUG and there is evidence for that on one Stack Overflow question.

Great!

Since in RecreateSandwichesApp we are using the test data we aren’t able to wrap any of that test data in the macro (because if…

--

--