No call to super.setUpWithError() in Xcode 11?
Asked Answered
C

1

12

I have noticed that when a new XCTestCase class is created with a default setUpWithError() and tearDownWithError() methods, there is no call to super.setUpWithError() or super.tearDownWithError() added anymore... If I am not mistaken, before, when I created a new Unit Test case class(a subclass of XCTestCase), in a default template class, there was a call to super.setUp() and super.tearDown() methods. Do you know why have these calls to super have been removed?

When a subclass of UIViewController is created, the default class template does have a call to super.viewDidLoad() for example. Why does a default template for XCTestCase does not have a call to super any more 🤨

Cumquat answered 7/4, 2020 at 15:54 Comment(3)
XCTest now includes throwing variants of the setUp() and tearDown() instance methods, allowing tests to throw errors in Swift during set up or tear down. Override the setUpWithError() or tearDownWithError() methods instead of setUp() or tearDown(), respectively. If an error is thrown by setUpWithError(), the test method is not executed, and if the error was due to calling an XCTSkip* API, the test is marked as skipped instead of failed. (42069831)Enquire
@developper thank you. Yes, I am aware about this. Xcode now adds tearDownWithError() rather than tearDown(). My question was about the absence of a call to super.tearDownWithError()Cumquat
Does this answer your question? Xcode 10 and super.tearDownChairmanship
S
1

When a test method runs, both setUpWithError and setUp are called. Thus, if you override setUpWithError and not setUp, and if your test situation already has a setUp implementation in the superclass, the superclass implementation will be called without your having to call super.

(And if your test situation has no setUp implemention in the superclass, there was no need to call super in the first place.)

Thus, the pattern shown by the template is correct.

Seafood answered 5/6, 2022 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.