The demo project to show how to organize code to make SwiftUI apps easy to be test.

Overview

TestableApp

I combined the idea to use functional programming instead of an loader instance in ModelView(I prefer to think of it as a service) and Resolver.

video

Functional signatures for loads or actions

typealias AsyncAction<T> = (T) async throws -> Void
typealias Loading<T> = () async throws -> T

How to use it in the app

@main
struct TestableApp: App {
    init() {
        Resolver.register {
            NewsService.initLoader()
        }
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

How to use it in a view for running

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Resolver.register {
            NewsService.mockLoader() //the app isn't running in canvas preview
//            NewsService.initLoader() //the app is running in canvas preview
        }
        
        return ContentView()
    }
}

How to use it in tests

class TestableAppTests: XCTestCase {
    private var service: NewsService!
    
    override func setUpWithError() throws {
        // Put setup code here. This method is called before the invocation of each test method in the class.
        Resolver.register {
            NewsService.mockLoader()
            
        }
        service = NewsService()
    }

    func testLoadingNews() async throws {
        XCTAssertEqual(service.news.count, 0)
        try await service.fetchAllNews()
        XCTAssertGreaterThan(service.news.count, 0)
    }
}
You might also like...
A simple iOS App that reads from the Test Flight News API

README Table of contents General info Unit Testing Technologies Revision Updates Setup General info SpaceFlight is a simple app built using the MVVM d

Free Market Selection Process Test
Free Market Selection Process Test

Prueba Proceso de Seleccion Mercado Libre (Xcode Version 13.0, iOS 15) Caracteristicas de la App SearchPortrait SearchLandscape DetailPortrait DetailL

Mac-asksec - Test Mac Permissions from the Terminal

asksec A simple CLI to test permissions from any macOS terminal app. Building ru

 ReactionButton is a control that allows developers to add this functionality to their apps in an easy way.
ReactionButton is a control that allows developers to add this functionality to their apps in an easy way.

Since Facebook introduced reactions in 2016, it became a standard in several applications as a way for users to interact with content. ReactionButton is a control that allows developers to add this functionality to their apps in an easy way.

SwiftWebUI - A demo implementation of SwiftUI for the Web
SwiftWebUI - A demo implementation of SwiftUI for the Web

SwiftWebUI More details can be found on the related blog post at the Always Right Institute. At WWDC 2019 Apple announced SwiftUI. A single "cross pla

COVID-19 SwiftUI Demo
COVID-19 SwiftUI Demo

COVID-19_SwiftUI_Demo About COVID-19_SwiftUI_Demo is the coronavirus information application using SwiftUI which is first introduced in WWDC19 keynote

A very simple Rick & Morty app to demo GraphQL + SwiftUI
A very simple Rick & Morty app to demo GraphQL + SwiftUI

MortyUI A very simple Rick & Morty app to demo GraphQL + SwiftUI Characters Character detail Episode This app have a very simple SwiftUI MVVM architec

A SwiftUI system components and interactions demo app
A SwiftUI system components and interactions demo app

SwiftUI Kit A SwiftUI system components and interactions demo app based on iOS 14, macOS Big Sur, watchOS 7, and tvOS 14. Use the SwiftUI Kit app to s

A demo of how you can integrate SwiftUI and Airtable in your app
A demo of how you can integrate SwiftUI and Airtable in your app

SwiftUI Airtable Demo This is a small, functional example app that demonstrates how you can use Airtable as a lightweight backend. I wouldn't recommen

Owner
VictorK
LinkedIn📘 https://www.linkedin.com/in/filimo
VictorK
Mahmoud-Abdelwahab 5 Nov 23, 2022
An iOS app demo to show list and detail screen of artworks.

Artworks iOS Demo Application Architecture MVP Clean Architecture (check Known Issues) Dependency Injection Features Localization Dark mode support Ba

Muhammad Adam 0 Dec 29, 2021
Project developed as part of a test task by RentaTeam

RentaTeamGiphy Project developed as part of a test task by RentaTeam. There is "endless" prefetching gallery of giphy preview pictures with play video

boogiedimik 0 Oct 9, 2021
This repository contains code for building Universal Apps with SwiftUI.

MindLikeWater This Repo This repository contains code for building Universal Apps with SwiftUI. The same codebase can be compiled to produce binaries

Jorge D. Ortiz Fuentes 1 Nov 23, 2021
A mobile application project designed for everybody which provides the easiest way to make searchs for public services

A mobile application project designed for everybody which provides the easiest way to make searchs for public services

null 0 Nov 23, 2021
ToDoList - An ios app that help users to set their todos and make it easy to remember this todos

An ios app that help users to set their todos and make it easy to remember this todos by reminders them when todo time's up, this app make sure that you don't forget any todos that you want to do just give it to the app and let the app hundle it for you.

Ahmed Mahrous 1 Apr 25, 2022
IOS15-SwiftUI-InAppPurchaseDemo - In-App Purchase Demo app written with SwiftUI

iOS15-SwiftUI-InAppPurchaseDemo In-App Purchase Demo app written with SwiftUI If

null 5 Jul 20, 2022
SwiftUI Backports - Introducing a collection of SwiftUI backports to make your iOS development easier

SwiftUI Backports Introducing a collection of SwiftUI backports to make your iOS development easier. Many backports support iOS 13+ but where UIKIt fe

Shaps 530 Dec 28, 2022
Simple app to show usage of SwiftUI and Combine

Podcasts Simple app to show usage of SwiftUI and Combine. The app shows a list of podcasts fetched from listennotes and it can be played. Status: Work

Alberto Penas Amor 27 Oct 4, 2022
Show What's New with SwiftUI.

SwiftNEWKit Accelerated by Apple SwiftUI Aims Provide an easy way for Apple Developers to Show "What's New" to the end users. Features Auto trigger th

MING 46 Jan 3, 2023