Questions tagged [xctestexpectation]

In Xcode 6, the XCTestExpectation class is a built-in support for asynchronous testing.

In Xcode 6, the XCTestExpectation class is a built-in support for asynchronous testing.

Useful link

62 questions
0
votes
1 answer

Unexpected behavior of XCTWaiter.wait

For testing purposes, I have the following test function: func test_wait() { var string: String? DispatchQueue.main.async { string = "set" print("string set") } let notNilPredicate = NSPredicate(format: "self !=…
Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
0
votes
1 answer

XCTestExpectation just hangs

I have no idea what's going on. I'm using an expectation in my test and it will not timeout. I've removed so much of my test that now I'm just left with: func testItem() { let expec = expectation(description: "expection") wait(for: [expec],…
Mr.P
  • 1,390
  • 13
  • 35
0
votes
0 answers

Expectation for notification is fulfilled without invoking handler block

In a unit test I have an expectation for notification which I provide to the method waitForExpectation: timeout:. The last one doesn't fail so the expectation is fulfilled. But the handler of the notification sometimes isn't being invoked. I know it…
0
votes
1 answer

XCTest sending information from the app (under test) back to XCTests

Situation: Consider an ios/swift/app that is being tested using xcode/XCTests. The app also includes some logging to console (and to Google/Firebase/Crashlytics as nonfatal exceptions: works great!). For this a custom written logging class is being…
HixField
  • 3,538
  • 1
  • 28
  • 54
0
votes
1 answer

Testing API call that happens at app launch results in multiple calls to fulfill

I am trying to implement Unit Testing for the first time on an existing app. First of all, contrary to what I see in tutorials, the app is launched as I try to run unit tests. I tried setting Host App to "None" on my test target, but ran into…
Jacobo Koenig
  • 11,728
  • 9
  • 40
  • 75
0
votes
0 answers

XCTest Conditional response

My app is a quiz. Responses required can be for: 1. Responses to questions - 5 possible answers 2. OK to prompt "Correct Answer" 3. OK to prompt "Wrong Answer" 4. OK to prompt "Game Level is " 5. OK to prompt "Game over" I have recorded the…
user3238267
  • 75
  • 1
  • 6
0
votes
1 answer

How can XCTestCase extensions that are called from a helper method know what properties were set on the main test case?

Background The following tests call a method that is an extension of XCTestCase. The goal: The waitForElementExists method returns because the element exists or The waitForElementExists method fails the test case/setUp method that called it…
0
votes
0 answers

XCTestExpectation example ios

I want to test webservice response using xctest in objective C. I am having some issues while using - (XCTestExpectation *)keyValueObservingExpectationForObject:(id)objectToObserve keyPath:(NSString *)keyPath expectedValue:(nullable…
0
votes
1 answer

XCTest: how can I tell which XCTestExpectation invoked 'fulfill'?

I'm testing a class that has a delegate. The delegate is the test class of course, and from the implementation of the delegate methods I call different expectations: - (void)mySuccess { [self.successExpectation fulfill]; } -…
Yotam
  • 9,789
  • 13
  • 47
  • 68
0
votes
1 answer

iOS9 XCTest - how to use expectations to test asynchronous cases without blocks?

I'm looking at this example of using asynchronous testing using iOS9 expectations. It makes sense for network requests and other operations that have completion blocks which can fulfill expectation. However, I'm attempting to unit test classes…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
0
votes
0 answers

XCTest: Crashing in XCTestExpectations in iOS

When I run my unit test scripts, it is crashing at ""waitForExpectationWithTimeout" in "ServiceTest" class. If I run test scripts for this "ServiceTest" class alone, then it is working properly without crash. But if I run test scripts for entire…
Coder
  • 1,661
  • 4
  • 27
  • 50
0
votes
0 answers

How to fail a async XCTestCase which crashes the test before calling completionHandler block?

I am doing iOS unit testing using XCTestCase and I am getting a crash due to "unrecognized selector" on async web service handler which returns manipulated NSDictionary by means of completionHandler block. The crash is not my expectation for…
The Debugger
  • 330
  • 8
  • 19
0
votes
1 answer

Manage multiple asynchronous operation on XCTests

I'm facing with a problem with asynchronous operations in a XCTestCase object. I started with a chain of expectation-waitForExpectation, sometimes passing the expectation instance as a method param to make it fulfilled by the asynchronous operation…
Luca D'Alberti
  • 4,749
  • 3
  • 25
  • 45
0
votes
1 answer

XCTest: Passing a function parameter

From XCTest file, I am calling a web service call and had put a wait block using "self.waitForExpectationsWithTimeout" API and to get the service response. I have few test methods to be executed with this service response. When I store this…
Coder
  • 1,661
  • 4
  • 27
  • 50
0
votes
0 answers

Tests get blocked when testing asynchronous network stuff with Nocilla

I'm trying to test a class that has a method responding asynchronously that makes a network call, stubbed by Nocilla. The tests runs fine when I run the test alone. But as soon as I launch my whole test suite, it blocks here for a while and finishes…
Mick F
  • 7,312
  • 6
  • 51
  • 98