blob: 9ff7f3af757cac4d243891410d8b2eb988561898 [file] [log] [blame]
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//
// XCAbstractTest.swift
// An abstract base class that XCTestCase and XCTestSuite inherit from.
// The purpose of this class is to mirror the design of Apple XCTest.
//
/// An abstract base class for testing. `XCTestCase` and `XCTestSuite` extend
/// `XCTest` to provide for creating, managing, and executing tests. Most
/// developers will not need to subclass `XCTest` directly.
public class XCTest {
/// Test's name. Must be overridden by subclasses.
public var name: String {
fatalError("Must be overridden by subclasses.")
}
/// Number of test cases. Must be overridden by subclasses.
public var testCaseCount: UInt {
fatalError("Must be overridden by subclasses.")
}
/// The `XCTestRun` subclass that will be instantiated when the test is run
/// to hold the test's results. Must be overridden by subclasses.
public var testRunClass: AnyClass? {
fatalError("Must be overridden by subclasses.")
}
/// The test run object that executed the test, an instance of
/// testRunClass. If the test has not yet been run, this will be nil.
/// - Note: FIXME: This property is meant to be `private(set)`. It is
/// publicly settable for now due to a Swift compiler bug on Linux. To
/// ensure compatibility of tests between swift-corelibs-xctest and Apple
/// XCTest, you should not set this property. See
/// https://bugs.swift.org/browse/SR-1129 for details.
public public(set) var testRun: XCTestRun? = nil
/// The method through which tests are executed. Must be overridden by
/// subclasses.
public func perform(_ run: XCTestRun) {
fatalError("Must be overridden by subclasses.")
}
/// Creates an instance of the `testRunClass` and passes it as a parameter
/// to `perform()`.
public func run() {
guard let testRunType = testRunClass as? XCTestRun.Type else {
fatalError("XCTest.testRunClass must be a kind of XCTestRun.")
}
testRun = testRunType.init(test: self)
perform(testRun!)
}
/// Setup method called before the invocation of each test method in the
/// class.
public func setUp() {}
/// Teardown method called after the invocation of each test method in the
/// class.
public func tearDown() {}
// FIXME: This initializer is required due to a Swift compiler bug on Linux.
// It should be removed once the bug is fixed.
public init() {}
}