Test Driven Development (TDD) is a discipline in agile software development. There are three laws of TDD:
The development flow of TDD is:
(Iteration start) -> Red -> Green -> Refactor -> (Next iteration)
Do as many quick iterations as needed until all requirements are met.
(P.s.: As we always get new requirements, this usually never ends 🤣)
import XCTest
@testable import UnitTestProject
class UnitTestProjectTests: XCTestCase {
...
}
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
continueAfterFailure: Bool
and executionTimeAllowance: TimeInterval
measure()
methodsexpectation()
methods for this.wait()
methodsXCTAssert()
methods for testing, e.g. boolean, nil and non-nil, equality, value comparison and other assertions, e.g.func testExample() throws {
let x = 0
XCTAssertTrue(x == 0, "Unexpected: x should be 0")
}
Testing asynchronous operations example (see here):
func testDownloadWebData() {
// Create an expectation for a background download task.
let expectation = XCTestExpectation(description: "Download apple.com home page")
// Create a URL for a web page to be downloaded.
let url = URL(string: "https://apple.com")!
// Create a background task to download the web page.
let dataTask = URLSession.shared.dataTask(with: url) { (data, _, _) in
// Make sure we downloaded some data.
XCTAssertNotNil(data, "No data was downloaded.")
// Fulfill the expectation to indicate that the background task has finished successfully.
expectation.fulfill()
}
// Start the download task.
dataTask.resume()
// Wait until the expectation is fulfilled, with a timeout of 10 seconds.
wait(for: [expectation], timeout: 10.0)
}
Source: Apple
In order to get your app through the Apple validation process, you should make sure that you meet Apples requirements concerning app behaviour (using only allowed frameworks) and also the Human Interface Guidelines: