6

So I am familiar with testing SwiftUI views, but how do I test the views used for the widget when they don't exist within the app after the app launches(As they are only being used within the widget)?

Additionally, what is the proper way to widget functions themselves (getTimeline etc.)?

I am still very new to iOS programming and want to understand the fundamentals of testing different iOS features. Any guidance would be much appreciated.

My basic project setup:

  • Data Models (Successfully Unit Tested)
  • Observable Object View Model that has API call functions (Successfully Unit Tested)
  • Default ContentView that is navigated to after tapping on the widget (No tests needed since the focus is on the widget)
  • WidgetView with the ObservedObject view model (No UI tests written)
  • Widget that uses the WidgetView (No UI/Unit tests written)
AK-Vitae
  • 61
  • 2
  • 1
    `WidgetView` will not be updated by your `ObservedObject`. Widgets work based on the timeline entries and are serialised. They will not be updated by model changes. Only way to update them is by refreshing the timeline. So I guess there is no point in creating `ObservedObject` view model for `WidgetView` and hence no testing required – user1046037 Nov 25 '22 at 21:58

0 Answers0