My team is starting to use the <experimental mock ...
# apollo-kotlin
r
My team is starting to use the experimental mock responses but we are running into an issue since our project is multi-module. Since the
TestBuilders
are being generated in our data modules test package, we cannot access them in other modules where we have acceptance tests. Has anyone found a way around this?
s
We’re doing this
Copy code
testDirConnection {
    // Make test builders available to main (not just test or androidTest) to be used by our mock data
    connectToAndroidSourceSet("main")
}
in our
apollo {}
gradle plugin configuration block to generate these test builders in the generated sources of the
main
directory instead of the test package. Would this help?
1
r
I’ll give that a try, thanks 🙂
That works, but exposes the test code to our production code. Will have to discuss with the team to see if they are ok with this. But thank you!
s
I am glad it works, but yes this is true. I don’t know of a better alternative, but if there is one, one of the library maintainers will probably know about it, so I’d wait for them to reply as well. I posted this as an idea to unblock you for now at least 😄
🙌 1
For us, we’re indeed exposing this to production code, but we’re only a few people so it’s easy to manually make sure we don’t accidentally use this in production. In a bigger team it may be harder to always be on the lookout 😄
r
I really appreciate it! Gives me some other ideas to try out too!
🥳 1
m
This is how I would do it too
I've heard about test fixtures in Java but IIRC it wasn't working very well in Kotlin
r
Ya I looked in to test fixtures but couldn’t get those working. Could certainly just have been doing something wrong.
m
I think there's an issue in the Kotlin tracker, let me check
😁 1
r
Ah bummer
m
You might be able to define a JVM-only module that defines the GraphQL queries
But not sure if you can "consume" the test fixtures from the Android module
r
I see. I’m looking in to creating a new source set which I could have the TestBuilders generated in that would be visible to other module tests but not to production code. I’m not sure if that’s possible or even makes sense as I haven’t dealt much with source sets before. But if this doesn’t work I’m going to look in to a JVM-only module as you described 👍
👍 1