Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mock lists in verifyNoMoreInteractions and verifyZeroInteractions #245

Open
gsvianna opened this issue Jul 5, 2024 · 0 comments

Comments

@gsvianna
Copy link

gsvianna commented Jul 5, 2024

I'm always frustrated when I have to use multiple verifyNoMoreInteractions and verifyZeroInteractions calls for different mocks in my tests. It would be more efficient and readable if these methods could accept a list of mocks.

I would like the verifyNoMoreInteractions and verifyZeroInteractions methods to support passing a list of mocks. This way, we can verify multiple mocks in a single call, making the test code cleaner and easier to maintain.

An alternative solution would be to create a custom helper function in my own test code to loop through the mocks and call verifyNoMoreInteractions or verifyZeroInteractions on each one. However, having this functionality built into the Mocktail package would be more convenient and beneficial for all users.

Here is an example of a test case where multiple verifyNoMoreInteractions and verifyZeroInteractions calls are used:

presenter = SomePresenter(
  mockA,
  mockB,
  mockC,
  mockD,
  mockE,
);

test('Some test case', () {
  when(() => mockA.getSomeData())
      .thenReturn(fakeData);

  presenter.doSomething();

  verifyInOrder([
    () => mockA.getSomeData(),
    () => mockB.trackAction(),
    () => mockC.updateView(any()),
  ]);

  verifyNoMoreInteractions(mockA);
  verifyNoMoreInteractions(mockB);
  verifyNoMoreInteractions(mockC);
  verifyZeroInteractions(mockD);
  verifyZeroInteractions(mockE);
});

To avoid using multiple verifyNoMoreInteractions and verifyZeroInteractions, my suggestion is to add support for passing a list of mocks to these methods.

presenter = SomePresenter(
  mockA,
  mockB,
  mockC,
  mockD,
  mockE,
);

test('Some test case', () {
  when(() => mockA.getSomeData())
      .thenReturn(fakeData);

  presenter.doSomething();

  verifyInOrder([
    () => mockA.getSomeData(),
    () => mockB.trackAction(),
    () => mockC.updateView(any()),
  ]);

  verifyNoMoreInteractions([mockA, mockB, mockC]);
  verifyZeroInteractions([mockD, mockE]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant