The primary class for defining test cases, test methods, and performance tests for iOS and Mac OS development.
Questions tagged [xctestcase]
226 questions
54
votes
4 answers
How to run one-time setup code before executing any XCTest
I have the following problem. I want to execute a piece of code before all test classes are executed. For instance: I don't want my game to use the SoundEngine singleton during executing, but the SilentSoundEngine. I would like to activate the…

Raymond
- 3,630
- 2
- 19
- 22
25
votes
4 answers
Unable To Run Unit Tests in Xcode 11: The run destination * is not valid for tests you have chosen to perform
Pretty sure my tests were running fine before I updated from Xcode 10.3 to Xcode 11. Now when I try to run a test I get the following error.
The run destination iPhone 5s is not valid for tests you have chosen to perform.
Please select a run…

Mark Bridges
- 8,228
- 4
- 50
- 65
22
votes
1 answer
XCTestCase to check if a method is called within a Struct
I am trying to test a piece of code where I check to see if an account has already created a secret key and stored it in the keychain. If not it calls a method that starts the oauth process.
My first thought was override the method which I would…

pls
- 1,522
- 2
- 21
- 41
17
votes
3 answers
XCTestCase: Wait for app to idle
My UI-test fails because the test waits endless until the app idles. I can not see that there is anything happening in the background, like a loading spinner.
It just occurs on one tab. All others tabs are tapable but the test fails on Screen 3. I I…

netshark1000
- 7,245
- 9
- 59
- 116
17
votes
2 answers
XCTestCase - iOS UI Tests - dealing with UITableViews with many cells
I am experimenting with the (Xcode 7) UI XCTestCase test cases and I just stumbled onto an issue with one UIView, in which I have a UITableView with many cells(4000+).
When the app is running normally, only the visible cells are rendered and there…

Integrating Stuff
- 5,253
- 2
- 33
- 39
16
votes
2 answers
Unable to monitor event loop AND Wait for app to idle
I am writing UITest cases for my app using XCTest. The app makes several server calls on the home screen. I could not navigate to the next screen. Automation often stays idle for 1 min or even more than that with the message
Wait for the app to…

Manoj
- 1,482
- 2
- 20
- 53
12
votes
1 answer
No call to super.setUpWithError() in Xcode 11?
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…

InterestedDev
- 578
- 7
- 22
10
votes
3 answers
Swift: XCTest Class 'FirstDemoTests' has no initializers
I have the following code (trying to avoid implicit unwrapping):
class MyTests: XCTestCase {
var viewController: ViewController
}
But I'm getting the following error:
Class 'MyTests' has no initializers
I fixed with this:
class MyTests:…

user2924482
- 8,380
- 23
- 89
- 173
9
votes
3 answers
Sending app to background and re-launching it from recents in XCTest
I was looking for a solution to my problem where in I need to send my app to background and re-launch it from the recents after a particular time interval.
deactivateAppForDuration() was used to achieve this in Instruments UIAutomation.
Does anybody…

rachit
- 1,981
- 15
- 23
9
votes
1 answer
In XCTest UI Testing, how to check the background color of button, label , views?
I am trying to validate if the background color can be obtained in XCTest UI Testing, I am looking to compare the background color with the set value, so that i don't have to rely on image comparison

abhishek saatal
- 295
- 1
- 3
- 14
8
votes
1 answer
XCTestCase with Auth0: How to dismiss security alert “XXXX” Wants to Use “auth0.com” to Sign In
So recently Apple introduced this prompt: “XXXX” Wants to Use “auth0.com” to Sign In
Where “XXXX” is the ios app name.
This alert/dialog comes up when in the case of Auth0 the user clicks on “Login with Google” or “Login with Facebook”. That’s all…

chrisl08
- 1,658
- 1
- 15
- 24
8
votes
1 answer
NSImage from Asset Catalog in Test Target
My unit tests target needs to load an image resource for use in some of the tests, but I am having trouble loading it.
I have created an asset catalog within the test target.
I have added a new image set resource to the catalog, checked the "Mac"…

Nicolas Miari
- 16,006
- 8
- 81
- 189
7
votes
1 answer
XCTest UITests fails at app launch with Expired token error
I am unable to run UI tests for a few days. It is failing while app launch portion with error
Expired token: no operation still exists for this token`.
If i run the whole class which contains more tests, most of them will fail for the same reason.…

ioana
- 93
- 4
7
votes
4 answers
How can you change orientation for testing on XCTest for iOS?
I'm trying to test my iOS app using XCTestCase in different orientations. I need a way to programmatic way to change the orientation. I tried doing this in 2 methods, but both didn't change the orientation (orientation remained as…

Meyyappan Nachiappan
- 95
- 2
- 4
6
votes
1 answer
How to Dynamically add XCTestCase
I'm writing a UI Test for a white label project where each app has a different set of menu items. The test taps on each menu item and takes a screenshot (using fastlane snapshot).
Currently this all happens inside one XCTestCase called…

Wez
- 10,555
- 5
- 49
- 63