I'm wondering if there is a way to use unit when XCtesting in order to specify a constant variable that isn't torn down between separate test cases? I realize that generally best practices for unit testing are to keep the tests as self contained as possible but in my current situation it would make the tests execute a lot faster if I were able to do this and keep a constant variable between test cases.
Currently, any type of init function that I call
override init() {
super.init()
}
Leaves me with an EXC_BAD_INSTRUCTION error. If I can't use init() in XCTestCase, is there another work around that I can use?
To run your app's XCTests on Test Lab devices, build it for testing on a Generic iOS Device: From the device dropdown at the top of your Xcode workspace window, select Generic iOS Device. In the macOS menu bar, select Product > Build For > Testing.
Overview. Use the XCTest framework to write unit tests for your Xcode projects that integrate seamlessly with Xcode's testing workflow. Tests assert that certain conditions are satisfied during code execution, and record test failures (with optional messages) if those conditions aren't satisfied.
You can disable XCTests run by Xcode by right clicking on the test symbol in the editor tray on the left. You'll get this menu, and you can select the "Disable " option.
Try moving the variable outside of the XCTestCase
class.
import XCTest
var counter = 0 // Note this is outside the class declaration
class MyTests: XCTestCase {
override func setUp() {
super.setUp()
counter++
print("Counter: \(counter)")
}
func testOne() {
...
}
func testTwo() {
...
}
func testThree() {
...
}
}
This gives an output like this.
...
Counter: 1
...
Counter: 2
...
Counter: 3
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With