'Mockito generate an invalid override for Methods that have as parameter an other generated class (generated from Moor)

We generate our database entities with moor. We have an database service as an facade for all database access. There we have the method Future<DatabaseEntry?> getDatabaseEntry(String entryId). DatabaseEntry is generated from moor.

In our test we have this

@GenerateMocks([DatabaseService])
void main() {...

In the mock from mockito we find this:

@override
  _i10.Future<dynamic> getDatabaseEntry(String? entryId) =>

and android studio is telling us correctly that

'MockDatabaseService.getDatabaseEntry' ('Future<dynamic> Function(String?)') isn't a valid override of 'DatabaseService.getDatabaseEntry' ('Future<DatabaseEntry?> Function(String)').

We think that this happens because Mockito generates the mocks before the DatabaseEntry class is generated from moor. How can we change the order of the build runners or is the problem somewhere else?



Solution 1:[1]

I know my answer is a bit late, but in my case I had a similar issue and this is how I solved it. What was happening is that the database call was a Future, and I was not awaiting the call, so it seems the compiler somehow does not know about what the method is stubbing is going to return if you are not waiting for it. Once you do that and generate the mocks once again you should be able to go. Let me know how it went.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matias