Open
Description
Spy was removed when we migrated to null safety. Spy also used the mirrors API which introduces problems on some platforms.
Are we able to implement the Spy feature using code gen? A potential spy implementation could be another layer ontop of a mock that proxies the calls to an instance that can be provided when creating the spy object.
Here is some pseudo code to show you how this feature can look like.
@GenerateMocks([Cat])
// This will generate the "SpyCat" class.
// We can also add `final List<Type> spyClasses` to the `GenerateMocks` annotation.
@SpyProxyMock([Cat])
void main() {
test(
"Example test",
() {
final spy = SpyCat(realInstance: Cat("liam"));
when(spy.eat(any)).thenAnswer((_) => print("..."));
},
);
}
In noSuchMethod
we can then decide if we have to call the realInstance
or if we execute a mocked invocation.
I would love to contribute to this feature.