correct it just works
# android
t
correct it just works
k
and all you did was
apply plugin: "kotlin-android-extensions"
? We're having a bit of trouble with them being
null
in Espresso 😕
t
I think the only other thing was to add
src/androidTest/kotlin
src set. what is the context of your consumption of the synthetic properties?
j
Checkout https://github.com/JoachimR/ThePokerGuys i made some espresso Tests there too
k
@trevjones we're using an
ActivityTestRule
to launch an activity, and then we're trying to call the synthetic view extensions on it. We don't use
src/X/kotlin
dirs, all of our Kotlin source is in the
src/X/java
folders, including for tests
a teammate of mine is writing these tests and reported this issue to me, maybe I'll poke around with it myself, but his issue sounded fairly straightforward 🤔
thanks Joachim, I will check out your app as well and see if there's anything we're doing differently
@joachim.reiss. hmm, it looks to me like your `androidTest`s are done using view IDs instead of the synthetic extensions?
j
Then i misunderstood what you meant sorry
t
I don’t think that srcSets would be related at all, just pointing out that it is the only other kotlin androidTest config change I have in gradle. In all the cases that I use the synthetic properties I am doing it on views that are inflated directly in my test case. The test case does use an activity test rule but only so I have a normal app compat activity to use as context for inflation. This all in concert with the facebook screenshot testing api’s. All that said if you can get a reference to the activity the synthetic properties should work against it assuming the activity has had onCreate called. My guess is that there is some misunderstanding in the way the activity test rules work? Let me find a blog post that goes into detail about how things changed depending on the activity rule params.
k
it's weird because finding the views by ID does work, the synthetic views are just null apparently
t
are you doing like
activity.some_view_id
or what are the specifics?
k
yes, that's what we're trying to do. But doing
activity.findViewById(R.id.some_view_id) as MyViewType
works fine, so it's confusing why the synthetic bindings don't find it
weird, seems that onCreate/Start/Resume are definitely called by the time your test case is run
t
what import are you using for the synthetics?
k
@trevjones sorry for the delay, didn't have time to work on this and had to jump to some other stuff. Hopefully you're still willing to help. 😛 The import is
import kotlinx.android.synthetic.main.fragment_add_venue_info.*
. Same import that we use in the actual classes and it works there I also tried running it just now, whatever issue we were having before (I was trying it out on my coworker's machine) is manifesting differently for me. We get a build error, with
Unresolved reference: fragment_add_venue_info
at the line with the import for the synthetic 😕