Closed kentcb closed 4 years ago
Hi Kent,
In my projects I use get_it with injectable. For tests I create a separate environment with injectable, which contains all services of the app, and replace all external 3rd-party dependencies (database, networking, analytics, etc) with mocks. During the initialization of the scenario I’m setting up these mocks, i.e. I have steps like “And the BE responds with an empty list” which I find intuitive and easy to read for non-technical folks in the team.
Here is a sample repository with this approach, and here is a video with some explanations.
Hope that helps!
Thanks for the quick response. That's actually very similar to what I ended up doing, so glad I'm on the right track!
Hello,
Is there any way to use riverpod
instead of get_it
for passing state through a scenario ?
Hey,
The package does not rely on get_it
, you may use riverpod
or any other package. What exactly you are trying to achieve?
Here is a sample repository with this approach, and here is a video with some explanations.
In this example, you use get_it
to access the mocked IAuthFacade and mock a response of the BE:
Future<void> theBeWillRejectAnyCredentials(WidgetTester tester) async {
final auth = getIt<IAuthFacade>();
when(auth.signInWithEmailAndPassword(
emailAddress: anyNamed('emailAddress'),
password: anyNamed('password')))
.thenAnswer(
(realInvocation) => Future.value(
left(
const AuthFailure.invalidEmailAndPasswordCombination(),
),
),
);
}
When using Riverpod, we need the ref
to access providers:
Future<void> theBeWillRejectAnyCredentials(WidgetTester tester) async {
final auth = ref.read(authProvider);
//...
}
But there's no way to have a ref
inside the step.
Hi,
Is there any support for passing state through a feature/scenario? I have abstracted all integration with the real world into APIs and have mocks of those APIs, but it's unclear how to best:
My only choice seems to be using a global variable for the mocks, which makes me somewhat uneasy.