Printing a mock variable causing methodToVerify being called under "Actual" count when used verify(()=>methodToVerify()).called(1);
- 主要語言
- Dart
- 星號
- 702
- 分支
- 88
- PR 合併指標
- 30 天內沒有已合併 PR
描述
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.
貢獻指南
這個儲存庫沒有索引到貢獻指南
評估
這個 Issue 還沒有評估資料。