mockito icon indicating copy to clipboard operation
mockito copied to clipboard

Need Assistance with Referencing Dummy Values Provided to provideDummy() in Mockito Tests

Open xIa066 opened this issue 1 year ago • 0 comments

I want to test method1 to verify that its retry functionality works correctly. In my system, the only way to trigger the retry is by invoking failure.onRetry(). Could you help me reference this failure in my test code so that I can call failure.onRetry() properly?

Here’s the code snippet for context:

test(
   'test method1',
   () async {
     MissingFieldFailure failure = MissingFieldFailure(
       fields: [],
       onRetry: service.method1(), // This is where the retry is triggered
       origin: 'test',
       package: 'test',
     );

   // Ignore the dummy rule for now
   provideDummy<Result<ApiResponseEntity>>(failure);

   await service.method1();

   await expectLater(
     service.method1(),
     emits(isA<MissingFieldFailure>()),
   );
 },
);

In the test, I’m setting up a MissingFieldFailure instance with an onRetry callback that is supposed to call service.method1(). However, I need a way to ensure that the retry is properly tested by referencing this failure and invoking failure.onRetry() in my test.

xIa066 avatar Sep 18 '24 04:09 xIa066