Skip to content

Commit

Permalink
Tweaked unbalanced rationale
Browse files Browse the repository at this point in the history
  • Loading branch information
mildm8nnered committed Feb 8, 2025
1 parent 419e698 commit cca8b99
Showing 1 changed file with 4 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,11 @@ struct BalancedXCTestLifecycleRule: Rule {
The `setUp` method of `XCTestCase` can be used to set up variables and resources before \
each test is run (or with the `class` variant, before all tests are run).
The memory model for XCTestCase objects is non-obvious. An instance of the `XCTestCase` \
subclass will be created for each test method, and these will persist for the entire test run.
This rule verifies that every class with an implementation of a `setUp` method also has \
a `tearDown` method (and vice versa).
So in a test class with 10 tests, given
```
private var foo: String = "Bar"
```
"Bar" will be stored 10 times over, but with
```
// swiftlint:disable:next implicitly_unwrapped_optional
private var foo: String!
func setUp() {
foo = "Bar"
}
func tearDown() {
foo = nil
}
```
no memory will be consumed by the value of the variable.
More generally, if `setUp` is implemented, then `tearDown` should also be implemented, \
and cleanup performed there.
The `tearDown` method should be used to cleanup or reset any resources that could \
otherwise have any effects on subsequent tests, and to free up any instance variables.
""",
kind: .lint,
nonTriggeringExamples: [
Expand Down

0 comments on commit cca8b99

Please sign in to comment.