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

"No such module" when using @testable in Xcode Unit tests

I recently updated to Xcode 7 beta 5. I tried adding a unit test to an earlier project, but I am getting the error message "No such module [myModuleName]" on the @testable import myModuleName line. I tried cleaning the project with Option Clean…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
187
votes
15 answers

Cannot load underlying module for XCTest

I'm working in swift on Xcode and by default it creates a test file that references XCTest. When I set the target membership to my main project it causes this error Cannot load underlying module for XCTest If this target membership is not set the…
brduca
  • 3,573
  • 2
  • 22
  • 30
140
votes
14 answers

Xcode Unit Testing with Cocoapods

I've been banging my head against a wall with this for the last few days but despite multiple Google/SO/Github searches I can't find a resolution to the issues I'm having! All I'm trying to do is create some unit tests for my app which makes use of…
doovers
  • 8,545
  • 10
  • 42
  • 70
126
votes
17 answers

How to let the app know if it's running Unit tests in a pure Swift project?

One annoying thing when running tests in Xcode 6.1 is that the entire app has to run and launch its storyboard and root view controller. In my app this runs some server calls that fetches API data. However, I don't want the app to do this when…
bogen
  • 9,954
  • 9
  • 50
  • 89
96
votes
3 answers

xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

I am using Xcode command line tools instead of XCode app in my MAC. When i use swift --version I get Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51) I cloned a project with git clone…
Sayan Sen
  • 1,654
  • 3
  • 16
  • 26
88
votes
18 answers

Is there a way to reset the app between tests in Swift XCTest UI?

Is there an API call within XCTest that I can put into the setUP() or tearDown() to reset the app between tests? I looked in the dot syntax of XCUIApplication and all I saw was the .launch() OR is there a way to call a shell script in Swift? I could…
Laser Hawk
  • 1,988
  • 2
  • 23
  • 29
88
votes
11 answers

XCTest/XCTest.h not found on old projects built in Xcode 6

I have a few projects I'm trying to build with Xcode 6 Beta 2. The projects all have some type of library that uses XCTest (Kiwi/XCTest and Specta) that don't build in Xcode 6 because XCTest/XCTest.h cannot be found. fatal error: 'XCTest/XCTest.h'…
Erik Kerber
  • 5,646
  • 7
  • 38
  • 56
84
votes
3 answers

XCTAssertEqual fails to compare two string values?

I added a simple unit test to test my string extension. But it fails. What I am I doing wrong here? From what I know XCTAssertEqual is testing value and not the object itself? The third line btw, says the string are equal, but XCTAssertEqual says…
Konrad77
  • 2,515
  • 1
  • 19
  • 36
83
votes
8 answers

NSURL to file path in test bundle with XCTest

I am trying to write an iOS app using TDD and the new XCTest framework. One of my methods retrieves a file from the internet (given a NSURL object) and stores it in the user's documents. The signature of the method is similar to: - (void)…
Eduardo Arenas Prada
  • 1,072
  • 1
  • 7
  • 14
75
votes
5 answers

How can I get XCTest to wait for async calls in setUp before tests are run?

I'm writing integration tests in Xcode 6 to go alongside my unit and functional tests. XCTest has a setUp() method that gets called before every test. Great! It also has XCTestException's which let me write async tests. Also great! However, I would…
Brett Elliot
  • 922
  • 1
  • 6
  • 9
73
votes
7 answers

When do app sources need to be included in test targets?

In a new project I have this simple test #import #import "ViewController.h" @interface ViewControllerTests : XCTestCase @end @implementation ViewControllerTests - (void)testExample { // Using a class that is not in the test…
Robert
  • 37,670
  • 37
  • 171
  • 213
55
votes
10 answers

Xcode 7 UI Testing: how to dismiss a series of system alerts in code

I am writing UI test cases using the new Xcode 7 UI Testing feature. At some point of my app, I ask the user for permission of camera access and push notification. So two iOS popups will show up: "MyApp Would Like to Access the Camera" popup and…
SeaJelly
  • 1,738
  • 1
  • 15
  • 30
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
53
votes
16 answers

Xcode 6 Editor doesn't recognize unit tests

I have a problem that the Xcode IDE 6 doesn't detect my swift unit test cases correctly. When I run the unit tests, all tests were executed. But in the IDE while editing the unit tests aren't recognized. I have to run the whole unit test suite in…
ChaosSpeeder
  • 3,468
  • 5
  • 30
  • 38
50
votes
7 answers

How to select a picker view item in an iOS UI test in Xcode?

I have a picker view with few items: "Red", "Green", "Yellow", "Black". In my UI test I need to select a specific item "Green" from it. I am using the XCTest UI testing APIs that were intruduced with Xcode 7. What I managed to do so far is to…
Evgenii
  • 36,389
  • 27
  • 134
  • 170
1
2 3
99 100