New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unittest should wait until all scheduled activities complete before ending a test #15094
Comments
I think you need an expectAsync call in there. See https://www.dartlang.org/articles/dart-unit-tests/#asynchronous-tests Added Area-Library, Library-UnitTest, NeedsInfo labels. |
This comment was originally written by Samuel....@gmail.com Ok, and how to write the test, that the callback will never get called? What is the purpose of protectAsync then? I am confused, I see no added value in wrapping function in protectAsync, if it isn't able to handle async calls. Reading the example at https://www.dartlang.org/articles/dart-unit-tests/#asynchronous-tests test('two callbacks', () { I thought that protectAsync can be used to ensure, that callback won't be called. expectAsync works perfectly in assuring, that the callback gets called. However, I want to assure exact opposite. |
Removed Area-Library label. |
Removed Area-Pkg, Library-UnitTest labels. |
Removed Area-UnitTest label. |
This comment was originally written by Samuel.Hapa...@gmail.com Have tested with new dart sdk 1.2 and unittest 0.10.0, nothing has changed. However, I see currently, that protectAsync is deprecated. What is then new recommended way to assure some asynchronous callback never gets called? |
test('two callbacks', () { The errorCallback will be called (it is is invoked) within the correct test context. |
The core issue here: once the last test completes, the test runner finishes and the host process is terminated. If the last test (or only test) schedules async work it might never be reported if the test system finishes. As a work-around you can return a future from the test with a delay. It might be possible to implement this as a feature in unittest, but I'm worried about the introduced complexit. Removed Type-Defect label. |
This comment was originally written by samuel....@vacuumapps.com I have also tried test("Protect call by throwing Error", () { But with no success. After looking through the source codes, I found that unittest simply ignores all errors that happen after the test suite ends. This should be easily fixable to at least print which test failed for what reason. However, it want help if you run tests using hop runner, which simply calls exit() which terminates all scheduled activities. But that is problem with hop runner. It seems, it would be great if runZoned could return some Future that completes when everything in zone finishes. We could use it then to determine whether the tests are still running. |
This issue has been moved to dart-lang/test#236. |
This issue was originally filed by Samuel....@gmail.com
What steps will reproduce the problem?
test("Protect async", () {
Timer.run(protectAsync0(() => expect(true, isFalse)));
});
What is the expected output?
Failed tests.
What do you see instead?
unittest-suite-wait-for-done
PASS: Protect async
All 1 tests passed.
unittest-suite-success
What version of the product are you using? On what operating system?
Linux, Dart 1.0.0.3_r30188
The text was updated successfully, but these errors were encountered: