0

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?

nilssimon
  • 11
  • 3

1 Answers1

0

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.

Matias
  • 708
  • 10
  • 24