I have this super basic app which changes the colour of a circle when you press a button:
struct ContentView: View {
@State private var color: Color = .red
var body: some View {
VStack {
Circle()
.frame(width: 100, height: 100)
.foregroundColor(color)
Button("Press me") {
color = color == .red ? .blue : .red
}
}
}
}
All I want to do is write a test which checks if the button appropriately changes the colour of the circle.
I only just read about all the unit testing and UI testing capabilities of Xcode but am unsure how to go about this. From the resources I've read online they all recommend either Snapshot Testing or using a package called ViewInspector
. However I just want to play around with the inbuilt capabilities of Xcode and am not looking for any rigorous testing frameworks or methods. Could someone tell me how Apple recommends to test SwiftUI Views? If there's no official/recommended way can someone tell me how to write a unit/UI test to check if the circle's colour changed appropriately.
Thanks in advance!