3
我有這樣的測試:飛鏢單元測試應該失敗的例外
Future f = neo4d.nodes.delete(1); f.then(((_) { })).catchError((e){ expect(e.statusCode, equals(409)); }); return f; });
,目前打擊了,因爲e.statusCode
是404而不是409我想測試只是失敗,而是整個測試套件停止由於未捕獲的異常。 如何捕獲異常(並且未通過測試),並阻止它炸燬所有其他測試?
這是輸出我得到的,當我運行上面的代碼:
[2014-03-06 14:44:32.020] DEBUG http: R10: Received data in 9ms with status 404: [{ "message" : "Cannot find node with id [1] in database.", "exception" : "NodeNotFoundException", "fullname" : "org.neo4j.server.rest.web.NodeNotFoundException", "stacktrace" : [ "org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:183)", "org.neo4j.server.rest.web.DatabaseActions.deleteNode(DatabaseActions.java:233)", "org.neo4j.server.rest.web.RestfulGraphDatabase.deleteNode(RestfulGraphDatabase.java:279)", "java.lang.reflect.Method.invoke(Method.java:601)", "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)", "java.lang.Thread.run(Thread.java:722)" ] }] Uncaught Error: Expected: 409 Actual: 404 Stack Trace: #0 SimpleConfiguration.onExpectFailure (package:unittest/src/simple_configuration.dart:141:7) #1 _ExpectFailureHandler.fail (package:unittest/src/simple_configuration.dart:15:28) #2 DefaultFailureHandler.failMatch (package:unittest/src/expect.dart:117:9) #3 expect (package:unittest/src/expect.dart:75:29) #4 nodes... (file:///Users/oskbor/Projects/neo4dart/test/alltests.dart:202:15) #5 _invokeErrorHandler (dart:async/async_error.dart:12) #6 _Future._propagateToListeners. (dart:async/future_impl.dart:469) #7 _rootRun (dart:async/zone.dart:683) #8 _RootZone.run (dart:async/zone.dart:823) #9 _Future._propagateToListeners (dart:async/future_impl.dart:445) #10 _Future._propagateMultipleListeners (dart:async/future_impl.dart:384) #11 _Future._propagateToListeners (dart:async/future_impl.dart:411) #12 _Future._completeError (dart:async/future_impl.dart:315) #13 _Future._asyncCompleteError. (dart:async/future_impl.dart:367) #14 _asyncRunCallback (dart:async/schedule_microtask.dart:18) #15 _createTimer. (dart:async-patch/timer_patch.dart:11) #16 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:151) #17 _Timer._createTimerHandler. (timer_impl.dart:166) #18 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:93) Unhandled exception: Expected: 409 Actual: 404 #0 _rootHandleUncaughtError.. (dart:async/zone.dart:677) #1 _asyncRunCallback (dart:async/schedule_microtask.dart:18) #2 _asyncRunCallback (dart:async/schedule_microtask.dart:21) #3 _createTimer. (dart:async-patch/timer_patch.dart:11) #4 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:151) #5 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:159) #6 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:159) #7 _Timer._createTimerHandler. (timer_impl.dart:166) #8 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:93)
關於奧斯卡