xctestexpectation

multiple asynchronous tests and expectation

孤人 提交于 2020-06-25 00:17:37
问题 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 fine. Each test works out correctly when done separately, but when I try to run the whole test class some tests pass and others crash or fail when they run and pass normally. I've looked all over online for "swift 3 multiple tests with expectation"

multiple asynchronous tests and expectation

落爺英雄遲暮 提交于 2020-06-25 00:16:29
问题 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 fine. Each test works out correctly when done separately, but when I try to run the whole test class some tests pass and others crash or fail when they run and pass normally. I've looked all over online for "swift 3 multiple tests with expectation"

TestCase : SwiftHTTP library not making the HTTP call

自闭症网瘾萝莉.ら 提交于 2020-01-13 11:38:08
问题 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 SwiftHTTP , since I found this much easier. On SwiftHHTP there is no way to know what URL got generated, what error it returned. For example, I tried to see the opt.debugDescription variable, it returned something cryptic like description String "

TestCase : SwiftHTTP library not making the HTTP call

孤街浪徒 提交于 2020-01-13 11:38:00
问题 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 SwiftHTTP , since I found this much easier. On SwiftHHTP there is no way to know what URL got generated, what error it returned. For example, I tried to see the opt.debugDescription variable, it returned something cryptic like description String "

XCTest: Crashing in XCTestExpectations in iOS

强颜欢笑 提交于 2020-01-06 20:23:19
问题 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 project, I am getting this crash. I am clueless on why and what this crash means. Appreciate any help. Thanks. 来源: https://stackoverflow.com/questions/33576790/xctest-crashing-in-xctestexpectations-in-ios

Nested function selector in swift for testing

左心房为你撑大大i 提交于 2019-12-12 06:19:33
问题 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 variables to a function in such a way that my notification handler can access them. My attempt was to make notification handler functions as nested functions inside my top level test function - but i've run into selector naming issues as I'm not sure

How to test async functions in swift using XCTWaiter and exceptions

寵の児 提交于 2019-12-11 17:35:02
问题 I want to test asynchronous functions in Swift, hence as shown below, I created a XCTestExpectation and passed it on to an XCTWaiter . Now, irrespective if the expectation is fulfilled or not, I get a test ran successfully always . Can you point out what is wrong in the code. I followed exactly a blog which was made for Swift 3, however, I am running Swift 4. Is that the issue? func testAsyncFunction() { let expectation = XCTestExpectation(description: "Some description") vc.asyncFunction(5)

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

南笙酒味 提交于 2019-12-10 12:56:47
问题 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 = ClassToTest() let expectation: XCTestExpectation = self.expectationWithDescription(nil) // test sut.methodToTestWithCompletionHandler() { () -> () in expectation.fulfill() } // verify self.waitForExpectationsWithTimeout(1, handler: nil) } However, if the completionHandler

TestCase : SwiftHTTP library not making the HTTP call

北战南征 提交于 2019-12-05 14:15:36
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 SwiftHTTP , since I found this much easier. On SwiftHHTP there is no way to know what URL got generated, what error it returned. For example, I tried to see the opt.debugDescription variable, it returned something cryptic like description String "<SwiftHTTP.HTTP: 0x60000007e540>" Steps I have followed I have set YES to Allow Arbitrary Loads . Safari on