How to provide test data and classes in multi-module gradle projects

Viewed 480

I want to provide downstream modules with test data/classes from an upstream module. What's the best way to do this?

Let's say I have the following modules:

:data-transactions - Has an interface TransactionsCache. This module by default will provide a TransactionDbCache which backs this cache with SQLite.

:ui-transactions - requires an instance of TransactionsCache to display the transactions to the user. This module is dependant on :data-transactions.

What I want

  • While testing :ui-transactions, I want to provide a fake implementation of TransactionsCache, like TransactionsInMemoryCache. Other downstream modules of :data-transactions may need TransactionsInMemoryCache too. This class should NOT be included in non-test modules.
  • These test dependencies like TransactionsInMemoryCache should be able to leverage kotlin the internal visibility modifier - i.e. be in the same module as :data-transactions

I'm guessing that the solution here is something to do with srcSets and a special testHelper configuration?

note: this is for android, so I'd need to generate an APK. is this possible without flavors?

1 Answers
Related