felangel / felangel/mocktail

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

Đang mở
#262 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
question waiting for response
Ngôn ngữ chính
Dart
Star
702
Fork
88
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.