79558155

Date: 2025-04-06 11:53:42
Score: 0.5
Natty:
Report link

Finally with tons of experiments I figure out the issue. In this scenario we don't want to create a Mock instance manually like below.

class MockMyService extends Mock implements MyService {}

Instead we only needs to annotate the needed class for mocking and run the command dart run build_runner build (as below code)

@GenerateMocks([RoleRepositoryImpl,MslDoctorFirebaseApi])
void main() {}

build runner creates a file with a name like xxxxxxxx.mocks.dart which contains a Mock class , which can be used for the testing.

Usually the the mock class starts with MOCK and follows the rest of the name of the class

eg: RoleRepository -> MockRoleRepositry.

import that to the test case , you will not get any errors

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Filler text (0.5): xxxxxxxx
  • Low reputation (0.5):
Posted by: Supun Ayeshmantha