Hello Everyone :slightly_smiling_face: I wanted to...
# gradle
r
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
commonTest
only applies within that module. other modules are only exposed to your
commonMain
(and other
*Main
) sources and dependencies
* except for test fixtures, those are also exposed… but also not totally ready in KMP
r
Is it a good practice to use
commonMain
for defining test dependency to make them transitive? Also, what is test fixture?
v
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
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
:some-repo:fake
to access
FakeSomeRepo
in another module's
commonTest{}
.
Copy code
// in :some-feature:viewmodel's build.gradle.kts
kotlin {
  commonTest.dependencies { 
     implementation(projects.someRepo.fake)
  }
}
That way you are not including your test doubles in production code.