You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Quick run its tests in a very specific (tree-based) order. Take the example below:
describe("MyClass"){// variable definition #1varsut:MyClass!varuserDefaultsMock:UserDefaults!// beforeEach #1beforeEach{/* ... */}// afterEach #1afterEach{/* ... */}// it #1it("exists"){/* ... */}// it #2it("conforms to the protocol ABC"){/* ... */}describe("tableView"){// it #3it("exists"){/* ... */}context("when user is logged out"){// beforeEach #2beforeEach{/* ... */}// it #4it("has the correct background color"){/* ... */}});
context("when user is logged in"){context("and has used Facebook login"){// beforeEach #3beforeEach{/* ... */}// it #5it("has the correct background color"){/* ... */}});
context("and has used Twitter login"){// beforeEach #4beforeEach{/* ... */}// it #6it("has the correct background color"){/* ... */}}}}}
The order of execution is:
Setup
variable definition # 1
Test 1
beforeEach # 1
it # 1
afterEach # 1
Test 2
beforeEach # 1
it # 2
afterEach # 1
Test 3
beforeEach # 1
it # 3
afterEach # 1
Test 4
beforeEach # 1
beforeEach # 2
it # 4
afterEach # 1
Test 5
beforeEach # 1
beforeEach # 3
it # 5
afterEach # 1
Test 6
beforeEach # 1
beforeEach # 4
it # 6
afterEach # 1
Variable definition isn't called again between tests and, for this reason, variable initialization should happen inside beforeEach blocks to avoid object state to be carried along the test file.
When the variable initialization happens outside a beforeEach and a test changes the object state, this will persist and might influence other tests. In other words, the following should be avoided:
rule request, opt-in, no calls inside describe and context blocks.
The text was updated successfully, but these errors were encountered:
ornithocoder
changed the title
Method calls and object initialization can be harmful inside Quick 'describe' and 'context' blocks
Method calls and object initialization inside Quick 'describe' and 'context' blocks can be harmful
Aug 16, 2017
ornithocoder
added a commit
to ornithocoder/personal-fork-swiftlint
that referenced
this issue
Aug 16, 2017
Quick run its tests in a very specific (tree-based) order. Take the example below:
The order of execution is:
Variable definition isn't called again between tests and, for this reason, variable initialization should happen inside
beforeEach
blocks to avoid object state to be carried along the test file.When the variable initialization happens outside a
beforeEach
and a test changes the object state, this will persist and might influence other tests. In other words, the following should be avoided:rule request, opt-in, no calls inside
describe
andcontext
blocks.The text was updated successfully, but these errors were encountered: