Is it required to call super in setup and tear down

Looking at Apple's documentation such as https://developer.apple.com/documentation/xctest/xctestcase/understanding_setup_and_teardown_for_test_methods and many another unit testing with XCTestCase examples, you can see that by convention, in `setUp` and `tearDown` methods, there's always a call to super. Looking at the ObjC version of XCTestCase, these calls are not annotated with the call to `super` being required.


When creating a new project with Xcode 10.1, the Unit Test template file doesn't have the call to super. What's the best practice? What's the right thing to do here?

Answered by DTS Engineer in 348312022

The superclass implementation of these methods are no-ops, and I’m pretty sure that’s always been the case. However, it would be nice if that was officially guaranteed by the documentation. In the absence of that, my recommendation is:

  • Keep calling super.

  • File a bug against the documentation requesting clarification.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

The superclass implementation of these methods are no-ops, and I’m pretty sure that’s always been the case. However, it would be nice if that was officially guaranteed by the documentation. In the absence of that, my recommendation is:

  • Keep calling super.

  • File a bug against the documentation requesting clarification.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you, eskimo! Here's the bug number for reference: 47745323.

@eskimo any news about it?

We did actually make changes as a result of this bug. Specifically, we tweaked Set Up and Tear Down State in Your Tests to remove the calls to super.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Is it required to call super in setup and tear down
 
 
Q