felangel / felangel/mocktail

Printing a mock variable causing methodToVerify being called under "Actual" count when used verify(()=>methodToVerify()).called(1);

Open
#262 2 comments 0 reactions 0 assignees View on GitHub
question waiting for response
Dominant language
Dart
Stars
702
Forks
88
PR merge metrics
No merged PRs in 30d

Description

I am trying to debug why there are 7 calls to the method theInitializer when I am just calling it once in the code and verifying that it is only being called once. Instead it is being called 7 times as captured by the verify().called() method.
Additionally, there are some print statements that are adding to the 7 calls everytime mockDIVariables.nums is mentioned in the print statements.
See the code below.

Here are the descriptions of the two methods above.
1. theInitializer method - Calculates the value of three variables, one of which is of type Function, all of which are passed to the loop method along with another variable obtained from a class containing only variables as part of a dependency injection strategy. So the theInitializer method looks like this-:
```dart
void theInitializer() async{
var var1=2,var2=3;
Function parameterFunction=(op1,op2)=>op1=op1+op2;
await loop(var1,var2,parameterFunction,diVariables.diList);
}
```
2. loop method - This method works with the variables to create some output which is stored in a variable called net. Something like below-:
```dart
Future loop(var var1,var var2,Function func,List diList){
for(int i=0;i mockDIVariables.nums).thenReturn([2, 2]);
listGeneration= ListGeneration(
diVariables: mockDIVariables,);
print(
'${mockDIVariables.nums} list ${mockDIVariables.nums[0]} ${mockDIVariables.nums[1]}');//These print statements count 2 calls of the streamNumbers method's called()'s actual count

test('arrayInitializer method test', () {
print('${mockDIVariables.nums} operation');//This print statements count 1 call of the streamNumbers method's called()'s actual count
listGeneration
.theInitializer(diVariables: mockDIVariables);
// print('${mockDIVariables.nums} operation 2');//This print statements count 1 call of the streamNumbers method's called()'s actual count
verify(() async=> await mockListGeneration.loop(99, const Duration(seconds: 1),
(op1, op2) => op1 += op2, mockDIVariables.nums)).called(7);
expect(listGeneration.net, 80);
});
});
}
```
I don't seem to understand what is it stemming from. I can only infer that it is a bug instead of a problem in my code. Please give your two cents.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.