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
35
votes
2 answers

How do I migrate from SenTestingKit/OCUnit to XCTest?

I am in the process of migrating my project from Xcode 4.6.3 to Xcode 5.0.2. The project's unit tests were developed with SenTestingKit/OCUnit. Now when I am running the tests in Xcode 5, I get an error from the RunUnitTests script telling me…
herzbube
  • 13,158
  • 9
  • 45
  • 87
34
votes
7 answers

XCode 5 unit testing: starts my app

When I run my tests in XCode 5, the main window of my OS X app appears on the screen for a couple of seconds while running the tests. Why? Even if I uncomment all my tests it still opens my main window.
dhrm
  • 14,335
  • 34
  • 117
  • 183
34
votes
1 answer

Clang Error: Reference to NSUTF8StringEncoding is ambiguous

I am trying to create unit tests using the new XCTest framework introduced in Xcode 5. I have a line in one of my test cases that looks like this: XCTAssertEqual([self.client stringEncoding], NSUTF8StringEncoding, …); When I try to run my tests,…
wjk
  • 1,219
  • 11
  • 27
33
votes
7 answers

Xcode 11 XCUITest Failed to get matching snapshots: Error getting main window kAXErrorServerNotFound

After building my app in Xcode 11 and running my suite of XCUITests I am getting many random failures with the following. Failed to get matching snapshots: Error getting main window kAXErrorServerNotFound No matter how long I increase timeouts the…
Luke Street
  • 441
  • 1
  • 4
  • 8
33
votes
2 answers

How can I run XCTest for a swift application from the command line?

I want to test drive some Swift examples using XCTest from the command line if possible. import XCTest class LeapTest : XCTestCase { func testVanillaLeapYear() { let year = Year(calendarYear: 1996) XCTAssertTrue(year.isLeapYear); …
John Paul Ashenfelter
  • 3,135
  • 1
  • 22
  • 29
32
votes
8 answers

Xcode7 | Xcode UI Tests | How to handle location service alert?

I am writing UI Test Cases for one one of my app using the XCUIApplication, XCUIElement and XCUIElementQuery introduced in Xcode7/iOS 9. I have hit a road block. One of the screens in test case requires iOS's Location Services. As expected the user…
Taha Samad
  • 1,135
  • 1
  • 9
  • 22
31
votes
5 answers

How to test that staticTexts contains a string using XCTest

In Xcode UI testing, how do I test that staticTexts contains a string? In the debugger, I can run something like this to print out all the content of staticTexts: po app.staticTexts . But how do I test if a string exists anywhere within all of…
Vincent Phillips
  • 445
  • 1
  • 5
  • 9
30
votes
3 answers

Xcode 5 throws "Library not loaded" error when adding a test target

I've tried adding a test target on Xcode 5 using the Add Target -> Add Cocoa Touch Unit Testing Bundle. However, when I run the test, I get the following error: 2013-09-24 10:43:14.446 Stack Exchange[48895:c07] Error loading …
Arie Litovsky
  • 4,893
  • 2
  • 35
  • 40
29
votes
4 answers

How do I clear unit test results in Xcode?

I'm having trouble clearing the test results for unit tests in Xcode 4. Basically, I ran a unit test which results in normal warnings. But, when I switch to regular bundle and run a build, the unit test results are still sticking around. Is there…
AWF4vk
  • 5,810
  • 3
  • 37
  • 70
29
votes
6 answers

Testing assertion in Swift

I'm writing unit tests for a method that has an assertion. The Swift Language guide recommends using assertions for "invalid conditions": Assertions cause your app to terminate and are not a substitute for designing your code in such a way that…
hpique
  • 119,096
  • 131
  • 338
  • 476
28
votes
3 answers

Use of undeclared type 'ViewController' when unit testing my own ViewController in Swift?

I have been trying to write test cases in Swift to test my ViewController. However, when I try to instantiate my own ViewController in a XCTestCase I get "Use of undeclared type 'ViewController' ". (ViewController is the name of my own…
hoomi
  • 1,882
  • 2
  • 16
  • 17
27
votes
4 answers

How can I run my performance tests more than ten times?

By default Xcodes performance tests are run ten times and my result is the average of those ten tests. The problem is the averaged result varies considerably each time I run it so I have to run the test at least five times to get a converged result.…
Declan McKenna
  • 4,321
  • 6
  • 54
  • 72
27
votes
2 answers

UI Test Case not show code coverage

I have some tests written using XCTestCase classes and I want to calculate code coverage. For the regular test it is shown nicely in my bot, but for UI Tests is always 0%. The simplest test: import XCTest class FAQUITests: XCTestCase { let app…
Jakub
  • 13,712
  • 17
  • 82
  • 139
27
votes
4 answers

Error loading XCTest, no suitable image found.

I have recently updated my Xcode and started having this error. 2014-11-03 15:03:54.222 App[13141:60b] Error loading /private/var/mobile/Applications/677127BD-5230-4D5F-B70E-AF728439D34B/tmp/AppTests.xctest/AppTests: …
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150
27
votes
5 answers

XCTAssertEqual: How to compare NSDates?

NSDate *date = [NSDate date]; XCTAssertEqual([[store selectedDate] timeIntervalSinceReferenceDate], [date timeIntervalSinceReferenceDate]); This gives me the error message: (([[store selectedDate] timeIntervalSinceReferenceDate]) equal to ([date…
Houman
  • 64,245
  • 87
  • 278
  • 460