I'd like to override the init function for XCTestCase in UI testing for a few reasons:
- To launch the app, outside of setUp() so that the app doesn't need to relaunch for every test (this is tedious and slows down tests)
- To initialize other classes that provide general navigation through the app, which must me initialized with a test case (self).
What I have now looks like this:
import XCTest
class UITest: XCTestCase {
let app = XCUIApplication()
// Helper packages
var helper: UITestHelper!
override func setUp() {
super.setUp()
// Helper package instantiation
helper = UITestHelper(withTestCase: self, forApp: app)
continueAfterFailure = false
app.launch()
}
... tearDown(), tests ....
When I call:
override init() {
super.init()
foo()
}
I get Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
lazy
variable but please don't do that. It will create a dependency between your tests. – Matchlock