上QQ阅读APP看书,第一时间看更新
Checking out test cases in a Vapor boilerplate project
Now that you've learned the basic workflow of how XCTest runs tests, it makes sense for you to check out the default test cases in a Vapor boilerplate project. The default test case template in a Vapor project gives you a bare-bones implementation of tests without any testing logic. It serves as a simple starting point for you to add more real tests to your project.
File: /Tests/AppTests/AppTests.swift
import App
import XCTest // [1]
final class AppTests: XCTestCase { // [2]
func testNothing() throws { // [3]
// add your tests here
XCTAssert(true) // [4]
}
static let allTests = [ // [5]
("testNothing", testNothing)
]
}
The following is a list of what the preceding bare-bones source code does:
- Imports the XCTest module
- Declares a new class by subclassing from XCTestCase
- Defines the first test function with a test prefix
- Adds a dummy assertion that always turns out to be true
- Defines a static array that contains all test functions
The macro XCTAssert() in [4] asserts a given Boolean expression to be true. Swift actually provides many different macros for test assertions. Next, you'll check out some of the assertion macros useful for your tests.