private
are silently skipped SW-W1016Marking unit tests as private in Swift can lead to several issues and is generally considered a bad practice. Here are a few reasons why: Test Visibility: Unit tests are essential for verifying the correctness of your code. By marking tests as private, you limit their visibility only to the file where they are defined. This means that other developers working on the same project may not be aware of the existence of those tests. It can make collaboration and code maintenance more difficult.
Code Coverage: When unit tests are marked as private, they are not executed as part of the test suite. This can lead to lower code coverage, as the private functionality might not be adequately tested. It increases the risk of undetected bugs in the codebase.
Refactoring Challenges: Tests serve as a safety net when making changes to your code. If tests are marked as private, they won't fail if the refactoring or modification of private code breaks the expected behavior. This defeats the purpose of having tests in the first place, as they should catch regressions and provide confidence in the codebase.
Documentation: Unit tests can serve as a form of documentation for other developers, especially when they are part of a testing suite that can be easily executed. By marking tests as private, you lose the opportunity to communicate the intended usage and behavior of the code to your colleagues.
In summary, marking unit tests as private in Swift undermines the purpose and benefits of testing, reduces code coverage, hinders collaboration, and makes code maintenance more challenging. It is generally recommended to keep unit tests as public or internal to ensure they are executed and serve their intended purposes effectively.
private class FooTest: XCTestCase {
func test1() {}
internal func test2() {}
public func test3() {}
private func test4() {}
}
class FooTest: XCTestCase {
func test1() {}
internal func test2() {}
public func test3() {}
}