Questions tagged [xctest]

XCTest is an Apple-provided framework which implements unit testing functions. It works with iOS 7 and all versions of OS X.

XCTest is a testing framework initially released with Xcode 5, provides a common framework for writing unit tests. XCTest supports unit testing for iOS, IPadOS, tvOS, watchOS, and macOS projects.

XCTest is part of the following SDKs:

  • Xcode 5.0 and later.

References

1962 questions
26
votes
9 answers

How to speed up UI test cases in Xcode?

Since Xcode 7 we have a nice API for UI testing. Mostly I'm satisfied with it. The only concern is related to the speed. In the beginning an ordinary UI test case (about 15 actions) ran approximately 25 seconds. Then I mocked networking completely.…
Artem Stepanenko
  • 3,423
  • 6
  • 29
  • 51
26
votes
3 answers

Replicate pull to refresh in XCTest UI testing

I am trying to replicate a pull to refresh on a UITableView using the new Xcode UI testing framework in Xcode 7 (beta 3) My current approach is dragging from the table to whatever element below the table I can find. This works when there is a fixed…
Kevin
  • 16,696
  • 7
  • 51
  • 68
26
votes
1 answer

How do I unit test HTTP request and response using NSURLSession in iOS 7.1?

I'd like to know how to "unit test" HTTP requests and responses using NSURLSession. Right now, my completion block code does not get called when running as a unit test. However, when the same code is executed from within the AppDelegate…
Jane Wayne
  • 8,205
  • 17
  • 75
  • 120
26
votes
1 answer

How to use XCTAssertThrowsSpecific

I'm writing Cocoa unit tests using XCTest and recently used XCTAssertThrows for the first time. That's pretty cool, but I want to make it even better with XCTAssertThrowsSpecific and requiring a certain exception. Here is an example…
owenfi
  • 2,471
  • 1
  • 24
  • 37
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
25
votes
5 answers

iOS XCUITests access element by accessibility

How do I assert a button exists by his accessibilityLabel or identifier? func testExitsButton() { XCTAssertTrue(app.windows.containing(.button, identifier: "Button Text").element.exists) XCTAssertTrue(app.buttons["Button Text"].exists) …
Godfather
  • 4,040
  • 6
  • 43
  • 70
25
votes
2 answers

UITesting, XCTest current ViewController Class

Simple problem. I got button which perform segue to next view controller. I want to write UI XCTest to tell me did it open view controller i wanted.
Dejan Zuza
  • 359
  • 1
  • 6
  • 14
25
votes
5 answers

Is it possible to run XCTest based tests under Instruments in Xcode 5?

Looking at XCTest and Xcode 5 unit testing and not seeing how to run my unit tests under Instruments in Xcode 5... Specifically I'd like to look for leaks during the test (this doesn't have to be automated in this instance, though clearly that'd be…
Dad
  • 6,388
  • 2
  • 28
  • 34
24
votes
4 answers

Swift too smart? Checking an objects type when testing with XCTest

I am aware there are a number of questions on how to get the type of an object using Swift. For example: How do you find out the type of an object (in Swift)? The reason that I want to find the type is so that I can test that the correct thing is…
Thomas Clowes
  • 4,529
  • 8
  • 41
  • 73
24
votes
10 answers

Test bundle could not be loaded because an unanticipated error

Recently I have started writing test case for one old static library. I have loaded the library to Xcode 5,Since Static Library is old , I have to manually add TestProject with Test Target. When I am trying "Product-->Test" , It launches emulator…
Brijesh Thakur
  • 6,768
  • 4
  • 24
  • 29
24
votes
3 answers

Accessing user defined variables passed in from xcodebuild command line

I am running my xctests using xcodebuild and need to pass in some environment variables. In the example below ACCOUNT_ID and HOST_URL. I tried passing in the variables as both environment variable and accessing them from the test using getenv…
wherewouldibe
  • 251
  • 1
  • 2
  • 5
24
votes
5 answers

failing a XCTestCase with assert without the test continuing to run but without stopping other tests

I'm trying to test my application using the XCTest framework. I want my single test case to fail if some logical condition holds (using an assertion). I don't want the rest of the code in the test case to run, because this might lead to problems…
Yoav Schwartz
  • 678
  • 1
  • 8
  • 18
23
votes
3 answers

XCTestExpectation: how to avoid calling the fulfill method after the wait context has ended?

I’m using the new asynchronous testing capabilities of Xcode 6. Everything works fine when the asynchronous task ends before the timeout. But if the task takes longer than the timeout, things get more complicated. Here is how I’m doing my…
0xced
  • 25,219
  • 10
  • 103
  • 255
23
votes
3 answers

Automatically Running a Test Case Many Times in Xcode

In Xcode, is there a way for me run a single test case n times automatically? Reason for doing this is that some of my beta testers are encountering random crashes in my app. I see the crash logs in TestFlight, along with the stack trace, but I…
Shinigami
  • 2,123
  • 23
  • 40
23
votes
3 answers

Using UIImage imageNamed inside XCTestCase

I can't get XCTestCase unit tests for a Cocoa Touch Static Library which rely on code that uses imageNamed to work. I added my image "plane.png" to the test target, but [UIImage imageNamed] keeps returning nil. When I explicitly specify the path of…
Pieter
  • 17,435
  • 8
  • 50
  • 89