We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
For normal func setUp and func tearDown we can convert them to init and deinit call on our test class according to the doc here.
func setUp
func tearDown
init
deinit
class
But what are the equivalents for class func setUp and class func tearDown here?
class func setUp
class func tearDown
class TestCaseBase: XCTestCase { override class func setUp() { // Class level init code print("[C] setup") } override class func tearDown() { // Class level deinit code print("[C] tearDown") } override func setUp() { // instance level init code ... print("[I] setup") } override func tearDown() { // instance level deinit code ... print("[I] tearDown") } func testMethod1() {} func testMethod2() {} }
We'll get
[C] setup [I] setup [I] tearDown [I] setup [I] tearDown [C] tearDown
After converting to swift-testing
swift-testing
@Suite class TestCaseBase { // 🚧 class func setUp() { // Class level init code print("[C] setup") } // 🚧 class func tearDown() { // Class level deinit code print("[C] tearDown") } init() { // instance level init code ... print("[I] setup") } deinit { // instance level deinit code ... print("[I] tearDown") } @Test func method1() {} @Test func method2() {} }
[I] setup [I] tearDown [I] setup [I] tearDown
Get the equivalents behavior of XCTest
XCTest
Missing class level setUp and tearDown code.
// Track it manually with `Bool` value to workaround class level setUp ```swift @Suite class AttributeTestBase { static var hasClassSetUp = false static var hasClassTearDown = false init() { if !Self.hasClassSetUp { // Ignore thread safety issues for now 🤔 Self.setUp() Self.hasClassSetUp = true } } deinit { ... } class func setUp() { ... } class func tearDown() { ... } } final class ATest: TestBase { init() { super.init() // instance level init code ... print("[I] setup") } deinit { // instance level deinit code ... print("[I] tearDown") } @Test func method1() { ... } @Test func method2() { ... } }
0.3.0
The text was updated successfully, but these errors were encountered:
Thank you, yes this is missing functionality we intend to add. I have explored this some so assigning to myself for now.
Sorry, something went wrong.
Duplicate of #36
stmontgomery
No branches or pull requests
Description
For normal
func setUp
andfunc tearDown
we can convert them toinit
anddeinit
call on our testclass
according to the doc here.But what are the equivalents for
class func setUp
andclass func tearDown
here?We'll get
After converting to
swift-testing
We'll get
Expected behavior
Get the equivalents behavior of
XCTest
Actual behavior
Missing class level setUp and tearDown code.
Workaround
swift-testing version/commit hash
0.3.0
The text was updated successfully, but these errors were encountered: