-
Notifications
You must be signed in to change notification settings - Fork 171
Open
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestcontributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)Contributions welcome to help resolve this (the resolution is expected to be clear from the issue)type-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
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.
stefanschaller, mrostock, TarekTolba1, mallle, JoshMart and 8 morestefanschaller, JoshMart and AmandaCleto
Metadata
Metadata
Assignees
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestcontributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)Contributions welcome to help resolve this (the resolution is expected to be clear from the issue)type-enhancementA request for a change that isn't a bugA request for a change that isn't a bug