Questions tagged [xctestcase]

The primary class for defining test cases, test methods, and performance tests for iOS and Mac OS development.

226 questions
2
votes
2 answers

How to check if an XCTestCase test has failed

Is it possible to check within a running test if any of its XCTAsserts have failed? I have a test with a few assertions in a row, and I want to add some code afterward to perform a specific action if any of them failed: class testClass :…
Stephen
  • 3,515
  • 5
  • 27
  • 33
1
vote
0 answers

Failed to run test cases : cannot test target on simulator

Cannot test target “FrameworkToolKitTests” on “iPhone 13 Pro Max” architectures: x86_64 Domain: XCTHTestRunSpecificationErrorDomain Code: 2 Using Xcode13.2.1 / testing framework code ,but testing not started Note: set (Enable testability : true )
Vivek Gajbe
  • 411
  • 2
  • 14
1
vote
1 answer

How to repeat a XCTestCase method n times?

I have found this question Can I run an XCTest suite multiple times? Which basically ask how to run XCTestCase suite multiple times. However, I would like to run only one method multiple times. How can I run for instance final class MyTests:…
1
vote
2 answers

Cannot access SwiftUI Text in XCTestCase UI Test

I am trying to add UI tests to a SwiftUI project. I have a list, which contains views - those then contain a number of views. I cannot seem to access the furthest most view in my UI test. I thought I could add an accessibility identifier to each…
Harry Blue
  • 4,202
  • 10
  • 39
  • 78
1
vote
1 answer

Xcode template doesn't pick the variable from popup

I'm writing an XCode template. Everything works perfectly fine if I use text value for the variable: Identifier appName Required true
laechoppe
  • 232
  • 3
  • 14
1
vote
1 answer

Access Button Tap In Unit test SwiftUI

I'm trying to access the button click in the Unit test class. I'm not able to perform action. Button AppCode:- var body: some View { VStack(spacing: 10) { Button(action: { print("Button Cicked") }) { …
Sham Dhiman
  • 1,348
  • 1
  • 21
  • 59
1
vote
1 answer

How to Get the ID for the Simulator that is generated in XCTestDevices

Is there a way to get the ID of the Simulator that is generated in the Library/Developer/XCTestDevices folder? When I do: UIDevice.current.identifierForVendor This gives me an ID but not the one I need: ▿ Optional some :…
reutsey
  • 1,743
  • 1
  • 17
  • 36
1
vote
1 answer

How can we test class which generates random states, and which can not generate same states twice?

We have three states.How can we test(with unit tests) our class which generates random state every 5 seconds, and which can not generate the same state twice in a row? The code of our random generator class is below ` final class…
1
vote
1 answer

Xcode 14.4 Sims XCUITest Get Simulator Alert Data Error - internal ObjC exception breakpoint

Using Xcode 12.4 Simulator 14.4 For the alert displayed below, I have the following function in my XCUITests that I use to pull the static text displayed on the System Alert: _ = addUIInterruptionMonitor(withDescription: "", handler: { (alert) ->…
reutsey
  • 1,743
  • 1
  • 17
  • 36
1
vote
1 answer

XCTestCase for opening camera and photo library

I have written a reusable class for opening camera and photo library as below class CameraAndPhotoManager: NSObject { var currentVC: UIViewController! func camera(vc: UIViewController) { currentVC = vc if…
Madhu
  • 439
  • 2
  • 14
1
vote
0 answers

iOS UI snapshot testing how to have different Reference Images folder for multiple targets

I have a project with 4 targets, since it's a whitelabel app, basically most of the code is common, except the branding (images, colors etc). I'm trying to set up UI Snapshots tests for each, but I want to avoid having duplicated code as well, so I…
Irina DM
  • 61
  • 3
1
vote
3 answers

How to test method that dispatch work asynchronously in Swift

I need to write the Unit Test for the following method func setLabelText(msg: String) { DispatchQueue.main.async { self.label.text = msg } }
Sajal Gupta
  • 147
  • 2
  • 14
1
vote
1 answer

SwiftUI XCTestCase - Cell never become hittable

I'm trying to execute a XCTestCase where I have a list of elements. In this case my cell exists and it passes the first XCTAssertTrue, but is never hittable and when enter inside the while cycle it never come out. Any solutions? Thanks. fileprivate…
1
vote
1 answer

XCTest Async Function Swift

i'm quite new to XCTest, i have structured my code in Model, View, Controller So controller will take data from Model and once got data, Controller will update View. So i have my Controller and view as follow Controller: func loadData() { …
wes. i
  • 627
  • 9
  • 26
1
vote
1 answer

IOS tests interacting with Mac file system

So I'm playing around with swiftui XCTestCase. I have a bunch of tests that run and get that they are running in the simulator or on the device. However - I now have a need to interact with the Mac I'm on - ie read and write to the Mac file system…
Darren Oakey
  • 2,894
  • 3
  • 29
  • 55