| OLD | NEW |
| 1 --- | 1 --- |
| 2 layout: default | 2 layout: default |
| 3 title: "Unit Testing with Dart" | 3 title: "Unit Testing with Dart" |
| 4 rel: | 4 rel: |
| 5 author: graham-wheeler | 5 author: graham-wheeler |
| 6 description: "Using Dart's unit test library for synchronous and asynchronous te
sts." | 6 description: "Using Dart's unit test library for synchronous and asynchronous te
sts." |
| 7 --- | 7 --- |
| 8 | 8 |
| 9 # Unit Testing with Dart | 9 # Unit Testing with Dart |
| 10 | 10 |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 throwsNotImplementedException | 434 throwsNotImplementedException |
| 435 throwsNullPointerException | 435 throwsNullPointerException |
| 436 throwsUnsupportedOperationException | 436 throwsUnsupportedOperationException |
| 437 | 437 |
| 438 So for example we can write: | 438 So for example we can write: |
| 439 | 439 |
| 440 test('Null Exception', | 440 test('Null Exception', |
| 441 expect(()=> throw new NullPointerException(), | 441 expect(()=> throw new NullPointerException(), |
| 442 throwsNullPointerException)); | 442 throwsNullPointerException)); |
| 443 | 443 |
| 444 <aside class="note"> | 444 <aside> |
| 445 <b>Note:</b> these type matchers (`isInstance` and `throwsA` plus its variants)
currently | 445 <div class="alert alert-info"> |
| 446 work in the Dart VM only; they do not work in Dart compiled to Javascript. | 446 <strong>Note:</strong> |
| 447 These type matchers (`isInstance` and `throwsA` plus its variants) currently |
| 448 work in the Dart VM only; they do not work in Dart compiled to Javascript. |
| 449 </div> |
| 447 </aside> | 450 </aside> |
| 448 | 451 |
| 449 For matching the inner content of compound objects, we have a number of matchers
, starting with the ubiquitous `equals()`: | 452 For matching the inner content of compound objects, we have a number of matchers
, starting with the ubiquitous `equals()`: |
| 450 | 453 |
| 451 equals(object, [depth]) | 454 equals(object, [depth]) |
| 452 | 455 |
| 453 This works with scalars, Maps and iterables (which should match in order). The d
epth parameter is to deal with cyclic structures; after [depth] comparisons the
match will fail if it has not already terminated. The default depth is 100. | 456 This works with scalars, Maps and iterables (which should match in order). The d
epth parameter is to deal with cyclic structures; after [depth] comparisons the
match will fail if it has not already terminated. The default depth is 100. |
| 454 | 457 |
| 455 Here is an example, taken from the JSON parse tests: | 458 Here is an example, taken from the JSON parse tests: |
| 456 | 459 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 MyFailureHandler() { | 598 MyFailureHandler() { |
| 596 errorCount = 0; | 599 errorCount = 0; |
| 597 // set this to be the expect() failure handler | 600 // set this to be the expect() failure handler |
| 598 configureExpectHandler(this); | 601 configureExpectHandler(this); |
| 599 } | 602 } |
| 600 void fail(String reason) { | 603 void fail(String reason) { |
| 601 ++errorCount; | 604 ++errorCount; |
| 602 } | 605 } |
| 603 } | 606 } |
| 604 | 607 |
| OLD | NEW |