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
1
vote
1 answer

What is the difference in semaphore vs the Expectation in iOS Unit Test for asynchronous api layer testing

I have implemented using semaphore and expectation , the result is same. What is the fundamental difference between both. // Using Expectation func testDownloadWithExpectation(){ let expect = expectation(description: "Download should…
garg
  • 2,651
  • 1
  • 24
  • 21
1
vote
2 answers

Correct timing/placement of XCTestExpectation fulfill method call in unit tests?

Consider the following unit test: - (void)testSample { XCTestExpectation *expectation = [self expectationWithDescription:@"Sample"]; [self.manager loadAllSuccess:^{ [expectation fulfill]; NSArray *data = [self.manager…
Zach
  • 3,909
  • 6
  • 25
  • 50
1
vote
0 answers

Asynchronous URLRequest data task times out

Attempting to get the following test working. It never enters the completion block and instead it times out after 30 seconds. The request seems like it is never made, as I can't see it on Charles. func testAsynchronousURLConnection() { let url =…
yorkie1990
  • 181
  • 1
  • 8
1
vote
1 answer

keyValueObservingExpectationForObject handler block not called

I have a testing case in Swift trying to wait for a property change: import XCTest class AsynchronyousKVOTests: XCTestCase { let testedObject : TestedObjet = TestedObjet.init() func testKeyValueObservingExpectationForObject() { …
Lukasz
  • 19,816
  • 17
  • 83
  • 139
1
vote
0 answers

Multiple expectations causes crash on waitForExpectationsWithTimeout

Here are the asynchronous functions I'm testing in Xcode using XCTestExpectation. -(void)syncData:(void (^)(NSString *type, NSError *error))completionBlock { [self fetchAWithCompletionBlock:^ { completionBlock(@"a",nil); }]; [self…
firecast
  • 988
  • 2
  • 10
  • 20
1
vote
1 answer

How to identify a JSON object using swift and xctest framework?

Using NSJSONSerialization.JSONObjectWithData(..) we can create a JSON object. But is it possible to identify the object type ie. is it a JSON object or not. I was just trying to check using Swift and XCTestFramework. I tried different ways but no…
1
vote
1 answer

isKindOfClass returning different values for Test Cases

I have a method someMethod. This method, at some point has the following if-else condition. - (void) someMethod { // ... some more code ... if ([userArray[0] isKindOfClass:[Me class]]) { // some code } else { // some…
Rahul Jiresal
  • 1,006
  • 13
  • 24
1
vote
1 answer

Nested function selector in swift for testing

Here is my situation and perhaps there is an easier way to do this: I'm testing some stuff that uses notifications and I didn't want to have to define my expectations as class level optional variables so I was wondering if I can make them local…
Jeef
  • 26,861
  • 21
  • 78
  • 156
1
vote
2 answers

xcodebuild unable to run asynchronous tests using XCTestExpectation?

I have three asynchronous tests. All run fine when tested within Xcode, but the test case cannot be built with xcodebuild. I get 11 build errors all relating to XCTestExpectation. Example: error: unknown type name 'XCTestExpectation' @property…
user3534641
  • 307
  • 2
  • 9
1
vote
1 answer

Unit testing code with PromiseKit usage

I'm trying to test Diary class that has dependency to Network. So Diary code: - (PMKPromise *)saveAndUploadToServer:(DiaryItem *)item { return [self save:item].then(^{ return [self upload:item]; << See UPDATE //I put breakpoint here, it…
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
0
votes
1 answer

Swift on Linux missing a method

I ran some tests on Swift for Linux today, using the swift:5.8-amazonlinux2 Docker container. I was surprised to find that the fulfillment(of:timeout:enforceOrder:) async method for asynchronously waiting on test expectations, and which resolves &…
jbelkins
  • 470
  • 3
  • 15
0
votes
0 answers

XCTest - How can I wait for an element from a given array of elements to become visible?

This is the flow I'm trying to cover - after I complete a certain action, some intermediary screens (let's say alerts) may or may not appear. If any of those intermediary alerts are shown, I need to to dismiss them. For this to be completed, I need…
0
votes
1 answer

Unit test async UI change in Swift

I am trying to unit test a custom UIView, which changes the UI asynchronously. This is the code for the custom view: import UIKit class DemoView: UIView { var label: UILabel! override init(frame: CGRect) { super.init(frame:…
Codey
  • 1,131
  • 2
  • 15
  • 34
0
votes
2 answers

Why is XCTest wait for expectation hanging an async background task?

I've been experiencing some failures in tests and I've worked out they appear to be caused by XCTest expectation waits suspending the Task instances. Even when they're on a background thread. Here's a made up test that's a vastly simplified version…
drekka
  • 20,957
  • 14
  • 79
  • 135
0
votes
1 answer

XCTKeyPathExpectation returns an unexpected error

I've tried to use XCTKeyPathExpectation in an async environment and could not get it to work. The error I'm getting is confusing me a lot. Because the error stated is not really an error in my opinion... I've created a very simple test to see if I…
Robert Veringa
  • 530
  • 4
  • 18