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

Using XCTest, how can one chain together multiple discrete sequences of { expectations -> wait }?

The documentation for XCTest waitForExpectationsWithTimeout:handler:, states that Only one -waitForExpectationsWithTimeout:handler: can be active at any given time, but multiple discrete sequences of { expectations -> wait } can be chained…
Elise van Looij
  • 4,162
  • 3
  • 29
  • 52
13
votes
2 answers

XCTest Assert Expectation wasn't fulfilled

When writing a certain asynchronous test using XCTest and XCTestExpectation I would like to assert that a certain block was not executed. The following code is successful in asserting that a block was executed and if not the test fails. #import…
Phillip Martin
  • 1,910
  • 15
  • 30
13
votes
1 answer

XCTAssert break function

How to stop unit test execution if a logic is failed. Below is the example. How to stop execution when XCTAssertEqual("Hello", "Hi", "Passed") condition is failed. func test_one() { XCTAssertEqual("Hello", "Hi", "Passed") let b =…
Coder
  • 1,661
  • 4
  • 27
  • 50
11
votes
3 answers

multiple asynchronous tests and expectation

I have multiple tests and each test is testing the same asynchronous method for different results with given parameters. I found out for asynchronous tests we have to declare an expectation, wait for expectation, and fulfil the expectation. This is…
Chirone
  • 191
  • 3
  • 11
8
votes
4 answers

Wait until object is not visible on the screen using Swift and XCTest

I'm looking for help writing a method which waits until the specified element is not present on a page anymore. I am developing with Swift 2.2 and XCTest. As you can see, I'm a new here and new to programming. Your help will be greatly appreciated.
8
votes
1 answer

XCTestCase waitForExpectationsWithTimeout:handler: throwing EXC_BAD_ACCESS when expectation is not fulfilled

I am testing an asynchronous call using XCTestExpectation. The following code works(the test succeeds) when the completionHandler is executed before the given 1 second timeout. func test__async_call() { // prepare let sut =…
e1985
  • 6,239
  • 1
  • 24
  • 39
6
votes
1 answer

Why does this Swift unit test crash when run in parallel with other tests?

I have a unit test that succeeds when it is run alone but crashes with an EXC_BAD_ACCESS (most of the time) on waitForExpectations when running alongside other tests. func testStartMonitoring() { let mockLocationManager = MockLocationManager() …
James Webster
  • 31,873
  • 11
  • 70
  • 114
6
votes
2 answers

What if XCTestExpectation is unexpected

I'm writing an XCTest unit test in Swift. The idea is that a callback mustn't be called in a certain case. So what I do, is func testThatCallbackIsNotFired() { let expectation = expectationWithDescription("A callback is fired") // configure…
Artem Stepanenko
  • 3,423
  • 6
  • 29
  • 51
5
votes
1 answer

UIControl's sendActions doesn't work in Test target

I'm trying to test that when UITextField sends editingChanged event special handler is invoked. So, for that purpose I simulate this event by sendActions method. But it doesn't work in Test target, all ok just in the project (Run mode - simulator).…
Nikita Ermolenko
  • 2,139
  • 2
  • 19
  • 41
4
votes
0 answers

iOS Test Suite crashes after running xctest.xctwaiter

This has been happening with xcode 9 and xcode10 now, using Quick and XCTest for unit tests they will run all the way fine but throw an exception/crash at the end. If I continue the tests will succeed. I've spent so many hours trying to figure…
JDM
  • 883
  • 1
  • 8
  • 20
4
votes
1 answer

TestCase : SwiftHTTP library not making the HTTP call

Important Fact I forgot to mention an important factor in the question. I am running this in a TestCase. I think this issue has something to do with the TestCase not awaiting for async completionHandler to return Migrated out from Alamofire to…
Siddharth
  • 9,349
  • 16
  • 86
  • 148
4
votes
0 answers

Asynchronous wait failed: Exceeded timeout of 10 seconds, with unfulfilled expectations: "messaage"

I am making an POST API call. I am running the UI test and wants to check the response of the URL. But I am getting an error when I run this test. Error:Asynchronous wait failed: Exceeded timeout of 10 seconds, with unfulfilled expectations:…
Danboz
  • 561
  • 1
  • 5
  • 14
4
votes
2 answers

XCTest passes when it should fail using expectations

I am testing a method that runs in background and executes a code block when it finishes. I am using expectations to handle the asynchronous execution of the tests. I wrote simple a test that shows the behaviour: - (void)…
martin
  • 247
  • 3
  • 15
3
votes
4 answers

test swift async function timeout

How do you write a unit test that checks whether an async function doesn't timeout? I'm trying with regular XCTestExpectation, but because await suspends everything, it can't wait for the expectation. In the code below, I'm checking that…
Eric
  • 16,003
  • 15
  • 87
  • 139
3
votes
1 answer

XCTWaiter().wait with XCTestExpectation and NSPredicate seems to fail

I am trying to write unit tests where I want my test case to wait for a variable in a certain class to change. So I create an expectation with a predicate and wait for the value to change using XCTWaiter().wait(for: [expectation], timeout: 2.0),…
gbroekstg
  • 1,055
  • 1
  • 10
  • 19
1
2 3 4 5