-
Notifications
You must be signed in to change notification settings - Fork 263
[SR-460] Provide XCTestCase a class to allow overriding setUp() and tearDown() #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mike-ferris
merged 6 commits into
swiftlang:master
from
briancroom:allow_setup_teardown_as_override
Mar 2, 2016
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c72f22a
Add functional test for the current behavior of setUp() and tearDown()
briancroom 261b8ca
Add failing setUp/tearDown test requiring source-compatibility Darwin…
briancroom b1f40a9
Add failing test for a new test case instance being used for each test
briancroom 1d51771
Changes to allow source-compatible tests and a new instance for each run
briancroom ef8bbe4
Update tests to meet the new requirements
briancroom 179d765
Update the README to correspond to the new API
briancroom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// RUN: %{swiftc} %s -o %{built_tests_dir}/TestCaseLifecycle | ||
// RUN: %{built_tests_dir}/TestCaseLifecycle > %t || true | ||
// RUN: %{xctest_checker} %t %s | ||
// CHECK: Test Case 'SetUpTearDownTestCase.test_hasValueFromSetUp' started. | ||
// CHECK: In setUp\(\) | ||
// CHECK: In test_hasValueFromSetUp\(\) | ||
// CHECK: In tearDown\(\) | ||
// CHECK: Test Case 'SetUpTearDownTestCase.test_hasValueFromSetUp' passed \(\d+\.\d+ seconds\). | ||
// CHECK: Executed 1 test, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds | ||
// CHECK: Test Case 'NewInstanceForEachTestTestCase.test_hasInitializedValue' started. | ||
// CHECK: Test Case 'NewInstanceForEachTestTestCase.test_hasInitializedValue' passed \(\d+\.\d+ seconds\). | ||
// CHECK: Test Case 'NewInstanceForEachTestTestCase.test_hasInitializedValueInAnotherTest' started. | ||
// CHECK: Test Case 'NewInstanceForEachTestTestCase.test_hasInitializedValueInAnotherTest' passed \(\d+\.\d+ seconds\). | ||
// CHECK: Executed 2 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds | ||
// CHECK: Total executed 3 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds | ||
|
||
#if os(Linux) || os(FreeBSD) | ||
import XCTest | ||
#else | ||
import SwiftXCTest | ||
#endif | ||
|
||
class SetUpTearDownTestCase: XCTestCase { | ||
static var allTests: [(String, SetUpTearDownTestCase -> () throws -> Void)] { | ||
return [ | ||
("test_hasValueFromSetUp", test_hasValueFromSetUp), | ||
] | ||
} | ||
|
||
var value = 0 | ||
|
||
override func setUp() { | ||
super.setUp() | ||
print("In \(__FUNCTION__)") | ||
value = 42 | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
print("In \(__FUNCTION__)") | ||
} | ||
|
||
func test_hasValueFromSetUp() { | ||
print("In \(__FUNCTION__)") | ||
XCTAssertEqual(value, 42) | ||
} | ||
} | ||
|
||
class NewInstanceForEachTestTestCase: XCTestCase { | ||
static var allTests: [(String, NewInstanceForEachTestTestCase -> () throws -> Void)] { | ||
return [ | ||
("test_hasInitializedValue", test_hasInitializedValue), | ||
("test_hasInitializedValueInAnotherTest", test_hasInitializedValueInAnotherTest), | ||
] | ||
} | ||
|
||
var value = 1 | ||
|
||
func test_hasInitializedValue() { | ||
XCTAssertEqual(value, 1) | ||
value += 1 | ||
} | ||
|
||
func test_hasInitializedValueInAnotherTest() { | ||
XCTAssertEqual(value, 1) | ||
} | ||
} | ||
|
||
XCTMain([ | ||
testCase(SetUpTearDownTestCase.allTests), | ||
testCase(NewInstanceForEachTestTestCase.allTests) | ||
]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-[XCTestCase invokeTest]
is a public method in Apple XCTest, although the Apple documentation does state that "in general this should not be called directly".Removing this method here isn't necessarily a blocker for merging this pull request, but it is one step backwards in terms of achieving API parity. Anyway just consider this a footnote of mine, as personally I think merging this pull request in order to get a correct
override func setUp()
is more important than keeping-invokeTest
around.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out, @modocache, I hadn't considered that method being a part of the XCTestCase API. Having looked at the docs now though, it seems that the current semantics of this method (run all the test methods in the test case) are significantly different than that of Xcode XCTest's (run a single test method). I would thus look at this as removing a potential point of confusion until such time as proper API compatibility may be attempted.