Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * Hooks to configure the unittest library for different platforms. This class | |
| 7 * implements the API in a platform-independent way. Tests that want to take | |
| 8 * advantage of the platform can create a subclass and override methods from | |
| 9 * this class. | |
| 10 */ | |
| 11 class Configuration { | |
| 12 /** | |
| 13 * Called as soon as the unittest framework becomes initialized. This is done | |
| 14 * even before tests are added to the test framework. It might be used to | |
| 15 * determine/debug errors that occur before the test harness starts executing. | |
| 16 */ | |
| 17 void onInit() {} | |
| 18 | |
| 19 /** | |
| 20 * Called as soon as the unittest framework starts running. Used commonly to | |
| 21 * tell the vm or browser that tests are still running and the process should | |
| 22 * wait until they are done. | |
| 23 */ | |
| 24 void onStart() {} | |
| 25 | |
| 26 /** | |
| 27 * Called when each test is completed. Useful to show intermediate progress on | |
| 28 * a test suite. | |
| 29 */ | |
| 30 void onTestResult(TestCase testCase) {} | |
| 31 | |
| 32 /** | |
| 33 * Called with the result of all test cases. The default implementation prints | |
| 34 * the result summary using the built-in [print] command. Browser tests | |
| 35 * commonly override this to reformat the output. | |
| 36 */ | |
| 37 void onDone(int passed, int failed, int errors, List<TestCase> results) { | |
| 38 // Print each test's result. | |
| 39 for (final test in _tests) { | |
| 40 print('${test.result.toUpperCase()}: ${test.description}'); | |
| 41 | |
| 42 if (test.message != '') { | |
| 43 print(' ${test.message}'); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 // Show the summary. | |
| 48 print(''); | |
| 49 | |
| 50 var success = false; | |
| 51 if (passed == 0 && failed == 0 && errors == 0) { | |
| 52 print('No tests found.'); | |
| 53 // This is considered a failure too: if this happens you probably have a | |
| 54 // bug in your unit tests. | |
| 55 } else if (failed == 0 && errors == 0) { | |
| 56 print('All $passed tests passed.'); | |
| 57 success = true; | |
| 58 } else { | |
| 59 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | |
| 60 } | |
| 61 | |
| 62 // A non-zero exit code is used by the test infrastructure to detect | |
|
eub
2012/04/10 21:52:24
"An exception is used ... to indicate failure"?
Siggi Cherem (dart-lang)
2012/04/10 22:15:17
Done.
| |
| 63 // failure. | |
| 64 if (!success) throw new Exception("Some tests failed."); | |
| 65 } | |
| 66 } | |
| OLD | NEW |