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

Viewed 2277

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

1 Answers

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.

Related