@@ -97,19 +97,24 @@ void main() {
97
97
98
98
test (
99
99
'makeDescription return a String with '
100
- 'formatted output by customDescriptionBuilder '
101
- 'and complex object as group description' , () {
100
+ 'formatted output by customDescriptionBuilder '
101
+ 'and complex object as group description' , () {
102
102
final values = [1 , 2 , 3 ];
103
103
104
104
Object ? builder (
105
- Object ? groupDescription,
106
- int index,
107
- List <dynamic > values,
108
- ) {
105
+ Object ? groupDescription,
106
+ int index,
107
+ List <dynamic > values,
108
+ ) {
109
109
return '[ $groupDescription | $index | ${values .length } ]' ;
110
110
}
111
111
112
- final result = pTest.makeDescription (DateTime (2024 ,04 ,17 ), 1 , values, builder);
112
+ final result = pTest.makeDescription (
113
+ DateTime (2024 , 04 , 17 ),
114
+ 1 ,
115
+ values,
116
+ builder,
117
+ );
113
118
114
119
expect (result, '[ 2024-04-17 00:00:00.000 | 1 | 3 ]' );
115
120
});
@@ -364,7 +369,9 @@ void main() {
364
369
expect (testMock.testCaptures[1 ].description, 3 );
365
370
expect (testMock.testCaptures[2 ].description, 4 );
366
371
});
372
+ });
367
373
374
+ group ('parameterized test exception handling tests' , () {
368
375
test (
369
376
'test throws ParameterizedError when length values and length '
370
377
'function arguments dont match' , () {
@@ -373,6 +380,7 @@ void main() {
373
380
pTest ('test' , [1 , 2 , 3 ], (int value, int value2) => value + value2),
374
381
throwsA (isA <ParameterizedError >()),
375
382
);
383
+
376
384
expect (
377
385
() => pTest (
378
386
'test' ,
@@ -387,13 +395,48 @@ void main() {
387
395
);
388
396
});
389
397
398
+ test (
399
+ 'nested test throws ParameterizedError when length values and length '
400
+ 'function arguments dont match' , () {
401
+ expect (
402
+ () => pTest (
403
+ 'test' ,
404
+ [1 , 2 , 3 ],
405
+ (int value) => pTest (
406
+ 'test' ,
407
+ [1 , 2 , 3 ],
408
+ (int value, int value2) => value + value2,
409
+ ),
410
+ ),
411
+ throwsA (isA <ParameterizedError >()),
412
+ );
413
+
414
+ expect (
415
+ () => pTest (
416
+ 'test' ,
417
+ [1 ],
418
+ (int value) => pTest (
419
+ 'test' ,
420
+ [
421
+ [1 , 2 ],
422
+ [3 , 4 ],
423
+ [5 , 6 ],
424
+ ],
425
+ (int value) => value,
426
+ ),
427
+ ),
428
+ throwsA (isA <ParameterizedError >()),
429
+ );
430
+ });
431
+
390
432
test (
391
433
'test throws ParameterizedError when values types and '
392
434
'function arguments types dont match' , () {
393
435
expect (
394
436
() => pTest ('test' , [1 , 2 , 3 ], (String value) => value),
395
437
throwsA (isA <ParameterizedError >()),
396
438
);
439
+
397
440
expect (
398
441
() => pTest (
399
442
'test' ,
@@ -408,10 +451,124 @@ void main() {
408
451
);
409
452
});
410
453
454
+ test (
455
+ 'nested test throws ParameterizedError when values types and '
456
+ 'function arguments types dont match' , () {
457
+ expect (
458
+ () => pTest (
459
+ 'test' ,
460
+ [1 , 2 , 3 ],
461
+ (int value) => pTest ('test' , [1 , 2 , 3 ], (String value) => value),
462
+ ),
463
+ throwsA (isA <ParameterizedError >()),
464
+ );
465
+
466
+ expect (
467
+ () => pTest (
468
+ 'test' ,
469
+ [1 ],
470
+ (int value) => pTest (
471
+ 'test' ,
472
+ [
473
+ [1 , 2 ],
474
+ [3 , 4 ],
475
+ [5 , 6 ],
476
+ ],
477
+ (int value, String value2) => value + value2.length,
478
+ ),
479
+ ),
480
+ throwsA (isA <ParameterizedError >()),
481
+ );
482
+ });
483
+
484
+ test ('test doesnt catch TypeError when the test body throws the exception' ,
485
+ () {
486
+ expect (
487
+ () => pTest ('test' , [1 , 2 , 3 ], (int value) {
488
+ // Causes a TypeError for test
489
+ // ignore: unused_local_variable
490
+ final error = value as String ;
491
+ }),
492
+ throwsA (isA <TypeError >()),
493
+ );
494
+ });
495
+
496
+ test (
497
+ 'nested test doesnt catch TypeError when the test body '
498
+ 'throws the exception' , () {
499
+ expect (
500
+ () => pTest (
501
+ 'test' ,
502
+ [1 , 2 , 3 ],
503
+ (int value) => pTest ('test' , [1 , 2 , 3 ], (int value) {
504
+ // Causes a TypeError for test
505
+ // ignore: unused_local_variable
506
+ final error = value as String ;
507
+ }),
508
+ ),
509
+ throwsA (isA <TypeError >()),
510
+ );
511
+ });
512
+
513
+ test (
514
+ 'test doesnt catch NoSuchMethodError when the test body '
515
+ 'throws the exception' , () {
516
+ expect (
517
+ () => pTest ('test' , [1 , 2 , 3 ], (int value) {
518
+ const dynamic errorCauser = '' ;
519
+
520
+ // This is a dynamic call, so it will throw a NoSuchMethodError
521
+ // ignore: avoid_dynamic_calls
522
+ errorCauser.whoop (1 , 2 );
523
+ }),
524
+ throwsA (isA <NoSuchMethodError >()),
525
+ );
526
+ });
527
+
528
+ test (
529
+ 'nested test doesnt catch NoSuchMethodError when the test body '
530
+ 'throws the exception' , () {
531
+ expect (
532
+ () => pTest (
533
+ 'test' ,
534
+ [1 , 2 , 3 ],
535
+ (int value) => pTest ('test' , [1 , 2 , 3 ], (int value) {
536
+ const dynamic errorCauser = '' ;
537
+
538
+ // This is a dynamic call, so it will throw a NoSuchMethodError
539
+ // ignore: avoid_dynamic_calls
540
+ errorCauser.whoop (1 , 2 );
541
+ }),
542
+ ),
543
+ throwsA (isA <NoSuchMethodError >()),
544
+ );
545
+ });
546
+
411
547
test ('test doesnt catch exceptions other than NoSuchMethodError, TypeError' ,
412
548
() {
413
549
expect (
414
- () => pTest ('test' , [1 , 2 , 3 ], (int value) => throw Exception ('test' )),
550
+ () => pTest (
551
+ 'test' ,
552
+ [1 , 2 , 3 ],
553
+ (int value) => throw Exception ('test' ),
554
+ ),
555
+ throwsA (isA <Exception >()),
556
+ );
557
+ });
558
+
559
+ test (
560
+ 'nested test doesnt catch exceptions other than '
561
+ 'NoSuchMethodError, TypeError' , () {
562
+ expect (
563
+ () => pTest (
564
+ 'test' ,
565
+ [1 , 2 , 3 ],
566
+ (int value) => pTest (
567
+ 'test' ,
568
+ [1 , 2 , 3 ],
569
+ (int value) => throw Exception ('test' ),
570
+ ),
571
+ ),
415
572
throwsA (isA <Exception >()),
416
573
);
417
574
});
0 commit comments