Skip to content

Instantly share code, notes, and snippets.

@ChrisMash
ChrisMash / ut_vertify_prereq_improved.swift
Last active October 16, 2023 19:33
A UT that does an improved job of verifying pre-requisites
verify(StorageThing)
.hasNoEntry("something")
sut = UnitBeingTested()
verify(StorageThing)
.hasEntry("something")
@ChrisMash
ChrisMash / ut_vertify_prereq_poor.swift
Last active October 16, 2023 19:32
A UT that does a poor job of verifying pre-requisites
sut = UnitBeingTested()
verify(StorageThing)
.hasEntry("something")
@ChrisMash
ChrisMash / ut_verify_expected_behaviour_improved.swift
Last active October 16, 2023 19:32
A UT that does an improved job of verifying expected behaviour
mockedDependency = mock(DependencyOfUnitBeingTested)
sut = UnitBeingTested("a value", mockedDependency)
verify(sut.value)
.is("a value")
verify(mockedDependency)
.callMadeTo(functionCalledByUnitBeingTested)
.withParameter("a value")
@ChrisMash
ChrisMash / ut_verify_expected_behaviour_poor.swift
Last active October 16, 2023 19:32
A UT that does a poor job of verifying expected behaviour
sut = UnitBeingTested("a value")
verify(sut.value)
.is("a value")
@ChrisMash
ChrisMash / ut_verify_unexpected_functions_improved.swift
Last active October 16, 2023 19:32
A UT that does an improved job of verifying unexpected function calls aren't made
delegate = ADelegate()
sut = UnitBeingTested(delegate)
sut.aFunctionCall()
verify(delegate)
.callMadeTo(onSuccess)
verify(delegate)
.callNOTMadeTo(onError)
@ChrisMash
ChrisMash / ut_verify_unexpected_functions_poor.swift
Last active October 16, 2023 19:31
A UT that does a poor job of verifying unexpected function calls aren't made
delegate = ADelegate()
sut = UnitBeingTested(delegate)
sut.aFunctionCall()
verify(delegate)
.callMadeTo(onSuccess)
@ChrisMash
ChrisMash / ut_verify_expected_values_improved.swift
Last active October 16, 2023 19:31
A UT that does an improved job of verifying expected values
delegate = ADelegate()
sut = UnitBeingTested(delegate)
sut.aFunctionCall()
verify(delegate)
.callMadeTo(functionOnDelegate)
.withParameter("1234")
@ChrisMash
ChrisMash / ut_verify_expected_values_poor.swift
Last active October 16, 2023 19:31
A UT that does a poor job of verifying expected values
delegate = ADelegate()
sut = UnitBeingTested(delegate)
sut.aFunctionCall()
verify(delegate)
.callMadeTo(functionOnDelegate)
.withParameter(anything())
@ChrisMash
ChrisMash / ProfileExpiryLogger.swift
Last active April 30, 2023 12:01
Example of updating an app's provisioning profile expiry time in a Firebase realtime database (gist for https://chris-mash.medium.com/using-provisioningprofile-and-firebase-to-monitor-profile-expiries-remotely-7832f475d7b7)
//
// Created by Chris Mash on 10/02/2022.
//
import UIKit
import ProvisioningProfile
import FirebaseDatabase
// NOTE: this gist uses some personal extensions I've written which aren't shared here but you should be able to swap out easily enough:
// Bundle.main.appVersion