Your First iOS & SwiftUI App: An App from Scratch

Feb 13 2023 · Swift 5.7, iOS 16, Xcode 14

Part 3: Coding in Swift

22. Intro to Unit Testing

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 21. The Swift Standard Library Next episode: 23. Intro to Test-Driven Development

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Like it or not, almost every program you’ll ever write will have bugs. It happens even to the best programmers. It’s just human nature - we’re imperfect!

Add Unit Testing

Alright so we want to add some unit tests to Bullseye here.

Add Tests

And then what we’re going to do here is, here’s the set up with error. Which as we discussed is where you do your initial setup for all of your tests.

class BullseyeTests: XCTestCase {
  var game: Game!
  override func setUpWithError() throws {
    game = Game()
  }
import XCTest
@testable import Bullseye
override func tearDownWithError() throws {
  game = nil
}
func testExample() throws {
  XCTAssertEqual(game.points(sliderValue: 50), 999)
}

Run the tests

Now that we have our test, there’s three ways that we can run this.