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
23
votes
5 answers

XCTest not registering new methods as tests

I have a seemingly weird problem (unless I'm missing something totally obvious!) and am curious if anyone here has any insight. I've done quite a bit of searching and haven't found anything. When I try and write unit tests in XCTest - creating new…
the1337sauce
  • 539
  • 4
  • 11
22
votes
3 answers

addUIInterruptionMonitor(withDescription:handler:) not working on iOS 10 or 9

The following tests works fine on iOS 11. It dismisses the alert asking permissions to use the locations services and then zooms in in the map. On iOS 10 or 9, it does none of this and the test still succeeds func testExample() { let app =…
Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121
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
22
votes
9 answers

Xcode 7.0 XCTest dyld: could not load inserted library IDEBundleInjection

I'm running unit tests on my iOS project and when it's running, it crashes and spits this out: dyld: could not load inserted library…
FireDragonMule
  • 1,347
  • 2
  • 16
  • 27
22
votes
2 answers

how to share the some pods in two target by podfile

xcodeproj 'Demo.xcodeproj' platform :ios, "6.0" target "Demo" do pod 'Demo-A', '3.1.1' pod 'Demo-B', '1.0' pod 'Demo-C', '~> 1.9.0' pod 'Demo-D', '~> 1.1' pod 'AA', '0.0.1' pod 'BB', '0.0.1' pod 'CC', '0.0.1' pod…
zixun
  • 257
  • 3
  • 6
22
votes
3 answers

Adding Swift files to test target not fixing unit tests

I have looked at a lot of blogs and tried many things to get my Swift unit tests to work in Xcode 6.0.1 (or 6.1 for that matter). I'm trying to access classes in my app's target so I wrote this line: var vc: LoginViewController! Of course, I get…
tfrank377
  • 1,858
  • 2
  • 22
  • 34
22
votes
6 answers

IBDesignable Errors When Adding to Tests Target

I have a simple UIButton subclass that implements IBDesignable with an IBInspectable var: @IBDesignable class Button: UIButton { @IBInspectable var borderColor: UIColor = UIColor.whiteColor() { didSet { layer.borderColor =…
Adolfo
  • 4,969
  • 4
  • 26
  • 28
22
votes
7 answers

What is the proper way to detect if unit tests are running at runtime in Xcode?

When I'm running unit tests, I'd like to skip some code (e.g. I don't want [[UIApplication sharedApplication] openURL:..] to run). I'm looking for a runtime check if I'm currently running units tests or not. I know I have seen code that checks the…
Ronald Mannak
  • 446
  • 1
  • 4
  • 11
22
votes
1 answer

Use of Unit Test in Xcode 5

I am writing my first bigger iOS project and I want to use as much of Xcode 5 as possible. Now I want to use testing but I have never done it before. My project uses come Views and dynamic `TableViews. How could I implement the test in the code, so…
Christian Seiler
  • 1,130
  • 1
  • 13
  • 29
21
votes
5 answers

Xcode UI Testing - typing text with typeText() method and autocorrection

I've got a test like below: let navnTextField = app.textFields["First Name"] let name = "Henrik" navnTextField.tap() navnTextField.typeText("Henrik") XCTAssertEqual(navnTextField.value as? String, name) Problem is that by default my iPhone…
Apan
  • 1,027
  • 2
  • 10
  • 27
21
votes
2 answers

XCUIElement - Obtain Image value

I have an variable that's of type .Image and class XCUIElement. Something like this: var image = app.descendantsMatchingType(.Image).elementAtIndex(0) Is there a way I can extract the actual image so I can compare it to another image? I've tried…
SalmonKiller
  • 2,183
  • 4
  • 27
  • 56
21
votes
3 answers

Why does passing an NSString object to the "format" parameter of XCTAssertTrue cause a build error?

In attempting to use XCTest to test my application, I get a build error when doing the following: #import @interface MyTests : XCTestCase @end @implementation MyTests - (void)testExample { NSString *str = @"foo"; …
akivajgordon
  • 8,761
  • 1
  • 19
  • 27
20
votes
2 answers

Xcode 11 simulators thrown a warning message each time a test is run

Running any XCTest with Xcode 11 and iOS 13/12 simulators throws the below warning message: xcodebuild[95489:2342933] [MT] DVTAssertions: Warning in …
mark w.
  • 1,047
  • 9
  • 16
20
votes
6 answers

XCTestAssertNil crash due to "nil" parameter

I'm using XCTest to write unit tests in my project, and when using the XCAssertNil() or XCAssertNotNil() methods, XCTest framework crashes. Here's my test: XCTAssertNotNil(messageCollection.fieldName, "field_name must be not-nil") Here's the stack…
sweepy_
  • 1,333
  • 1
  • 9
  • 28
20
votes
4 answers

Can't import main swift classes into test target?

I am trying to test the classes in my iOS app. I am trying to import the target Pickle in my app that has all my classes into my testing target PickleTests by adding import Pickle to the top of my PickleTests.swift testing file, but I keep getting…
dcgoss
  • 2,147
  • 3
  • 20
  • 31