I am trying to write simple tests for my iOS application in Swift using Quick/Nimble with Nocilla to imitate network calls. Here is simple stub that I have:
let settingsToReturn = ["LogLevel":"Verbose", "FrequencySeconds":21600, "NumberOfFiles":5]
expect { settingsData = try NSJSONSerialization.dataWithJSONObject(settingsToReturn, options: NSJSONWritingOptions.PrettyPrinted) }.toNot(throwError())
stubRequest("GET", myURL)
.withHeaders(["Accept": "application/json"])
.andReturn(200)
.withBody(settingsData)
When I run my tests, I get the following exception:
2016-06-10 11:57:20.869 xctest[57106:7484697] *** Terminating app due to uncaught exception 'NocillaUnexpectedRequest', reason: 'An unexpected HTTP request was fired.
Use this snippet to stub the request:
stubRequest(@"GET", myURL).
withHeaders(@{ @"Accept": @"application/json" });
'
*** First throw call stack:
(
0 CoreFoundation 0x00b28494 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x005e2e02 objc_exception_throw + 50
2 CoreFoundation 0x00b283bd +[NSException raise:format:] + 141
3 Nocilla 0x0aaa3160 -[LSNocilla responseForRequest:] + 880
4 Nocilla 0x0aaa1e98 -[LSHTTPStubURLProtocol startLoading] + 168
5 CFNetwork 0x036ed9b8 _ZN16CFURLProtocol_NS28_protocolInterface_startLoadEPK20_CFCachedURLResponse + 324
6 CFNetwork 0x037effe4 ___ZN19URLConnectionLoader27_private_ScheduleOriginLoadEPK12NSURLRequestPK20_CFCachedURLResponse_block_invoke_2 + 62
7 CFNetwork 0x036c7428 ___ZNK19URLConnectionLoader25withExistingProtocolAsyncEU13block_pointerFvP11URLProtocolE_block_invoke + 30
8 libdispatch.dylib 0x033156ed _dispatch_client_callout
Test session log:
/Users/mihailtihonchik/Library/Developer/Xcode/DerivedData/EMKit-bqvwvziharwleuevxdnfzuxqfgnt/Logs/Test/C61E0663-D7C2-4002-8B97-A57F5BF44CB5/Session-2016-06-10_11:57:12-N8W1nL.log
14
9 libdispatch.dylib 0x032fa218 _dispatch_block_invoke + 377
10 libdispatch.dylib 0x03312f08 ___dispatch_block_create_block_invoke + 20
11 CFNetwork 0x036c73fa _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 24
12 CoreFoundation 0x00a0b1f9 CFArrayApplyFunction + 57
13 CFNetwork 0x036c72f5 _ZN19RunloopBlockContext7performEv + 143
14 CFNetwork 0x038873da _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
15 CFNetwork 0x036c71b2 _ZN17MultiplexerSource7performEv + 326
16 CFNetwork 0x036c6fca _ZN17MultiplexerSource8_performEPv + 76
17 CoreFoundation 0x00a3ae5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x00a30aeb __CFRunLoopDoSources0 + 523
19 CoreFoundation 0x00a2ff08 __CFRunLoopRun + 1032
20 CoreFoundation 0x00a2f846 CFRunLoopRunSpecific + 470
21 CoreFoundation 0x00a2f65b CFRunLoopRunInMode + 123
22 CFNetwork 0x03764036 +[NSURLConnection(Loader) _resourceLoadLoop:] + 472
23 Foundation 0x001efeda -[NSThread main] + 76
24 Foundation 0x002a52dc __NSThread__start__ + 1346
25 libsystem_pthread.dylib 0x0363e780 _pthread_body + 138
26 libsystem_pthread.dylib 0x0363e6f6 _pthread_body + 0
27 libsystem_pthread.dylib 0x0363bf7a thread_start + 34
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I looked at numerous examples online, and I don't see much of the difference between that code and mine. One thing to note, if I remove last two lines
.andReturn(200)
.withBody(settingsData)
the exception is not thrown. But then I am not really testing the payload that is being brought back.
Aucun commentaire:
Enregistrer un commentaire