I want to do some unit tests on some functions, but I need to execute all the tests after the completion of a Future.
To develop my problem, Here an example of what I want to do :
registerToServer(contentOfRequest).then((id){
test('test function1', () {
function1(id, contentOfRequest).then(expectAsync((val){
expect(val, whatIExpect);
}));
});
test('test function2', () {
function2(id, contentOfRequest).then(expectAsync((val){
expect(val, whatIExpect);
}));
}):
...
};
I have tried with a alternate solution, but this does not change anything :
String id;
registerToServer(contentOfRequest).then((sid){
id = sid;
}).then((_){
test('test function1', () {
function1(id, contentOfRequest).then(expectAsync((val){
expect(val, whatIExpect);
}));
});
test('test function2', () {
function2(id, contentOfRequest).then(expectAsync((val){
expect(val, whatIExpect);
}));
}):
...
};
And I would have, if possible the tests organize as that, as I want a description for all the tests.
The stacktrace is something like that :
Unhandled exception:
Uncaught Error: Bad state: Not allowed when tests are running.
Stack Trace:
#0 _requireNotRunning (package:unittest/unittest.dart:430:3)
#1 test (package:unittest/unittest.dart:100:21)
#2 main.<anonymous closure> (file:///.../server_test.dart:260:11)
#3 _RootZone.runUnary (dart:async/zone.dart:1155)
#4 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:484)
#5 _Future._propagateToListeners (dart:async/future_impl.dart:567)
#6 _Future._completeWithValue (dart:async/future_impl.dart:358)
#7 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:412)
#8 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#9 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#10 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#11 _startIsolate (dart:isolate-patch/isolate_patch.dart:244)
#12 _startMainIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:192)
#13 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:130)
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:886)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#4 _startIsolate (dart:isolate-patch/isolate_patch.dart:244)
#5 _startMainIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:192)
#6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:130)