Empty XCTest Method

Empty XCTest method should be avoided

  • Identifier: empty_xctest_method
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: lint
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning
    test_parent_classes [“QuickSpec”, “XCTestCase”]

Non Triggering Examples

class TotoTests: XCTestCase {
    var foobar: Foobar?

    override func setUp() {
        super.setUp()
        foobar = Foobar()
    }

    override func setUpWithError() throws {
        foobar = nil
    }

    override func tearDown() {
        foobar = nil
        super.tearDown()
    }

    func testFoo() {
        XCTAssertTrue(foobar?.foo)
    }

    func testBar() {
        // comment...

        XCTAssertFalse(foobar?.bar)

        // comment...
    }

    func testBaz() {
        _ = 4 + 4
    }
}
class Foobar {
    func setUp() {}

    func tearDown() {}

    func testFoo() {}
}
class TotoTests: XCTestCase {
    func setUp(with object: Foobar) {}

    func tearDown(object: Foobar) {}

    func testFoo(_ foo: Foobar) {}

    func testBar(bar: (String) -> Int) {}
}
class TotoTests: XCTestCase {
    func testFoo() { XCTAssertTrue(foobar?.foo) }

    func testBar() { XCTAssertFalse(foobar?.bar) }
}
class TotoTests: XCTestCase {
    override class var runsForEachTargetApplicationUIConfiguration: Bool { true }

    static var allTests = [("testFoo", testFoo)]

    func testFoo() { XCTAssert(true) }
}

Triggering Examples

class TotoTests: XCTestCase {
    override func setUp() {
    }

    override func tearDown() {

    }

    func testFoo() {


    }

    func testBar() {



    }

    func helperFunction() {
    }
}
class TotoTests: XCTestCase {
    override func setUp() {}

    override func tearDown() {}

    func testFoo() {}

    func helperFunction() {}
}
class TotoTests: XCTestCase {
    override func setUp() {
        // comment...
    }

    override func tearDown() {
        // comment...
        // comment...
    }

    func testFoo() {
        // comment...

        // comment...

        // comment...
    }

    func testBar() {
        /*
         * comment...
         *
         * comment...
         *
         * comment...
         */
    }

    func helperFunction() {
    }
}
class FooTests: XCTestCase {
    override func setUp() {}
}

class BarTests: XCTestCase {
    func testFoo() {}
}