Hello Everyone 🙂
I wanted to ask about declaring test dependencies as
api
instead of
implementation
When we define some test-dependency for a module, eg -
testing
, like this:
Copy code
commonTest.dependencies {
api(compose.uiTest)
}
Then we cannot access that dependency in a module where I'm implementing
testing
module. However, using api should make the dependency transitive but it didn't. Is it a bug or a feature? Because I can easily access the dependency if I define it inside
commonMain
source-set using
api
.
Please let me know if anyone face this issue and how to deal with it. Thanks :)
e
ephemient
05/01/2025, 4:06 PM
commonTest
only applies within that module. other modules are only exposed to your
commonMain
(and other
*Main
) sources and dependencies
ephemient
05/01/2025, 4:07 PM
* except for test fixtures, those are also exposed… but also not totally ready in KMP
r
Rohit Verma
05/01/2025, 4:08 PM
Is it a good practice to use
commonMain
for defining test dependency to make them transitive? Also, what is test fixture?
It is never a good idea to use transitive dependencies. You should declare what you use where you use it. Only things in your public API (parameter types, super types, return types, ...) should be
api
.
r
Richard Leggett
05/02/2025, 8:56 AM
If you want e.g. fakes to be exposed to other modules' test source sets you can structure your sub-projects like so:
• some-repo
â—¦ interface (/api)
â—¦ impl
â—¦ fake
Then consume