https://kotlinlang.org logo
#android
Title
# android
t

trevjones

04/18/2017, 8:06 PM
correct it just works
k

kevinmost

04/18/2017, 9:45 PM
and all you did was
apply plugin: "kotlin-android-extensions"
? We're having a bit of trouble with them being
null
in Espresso 😕
t

trevjones

04/18/2017, 10:00 PM
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

joachim.reiss.

04/18/2017, 10:46 PM
Checkout https://github.com/JoachimR/ThePokerGuys i made some espresso Tests there too
k

kevinmost

04/19/2017, 3:20 PM
@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

joachim.reiss.

04/19/2017, 3:24 PM
Then i misunderstood what you meant sorry
t

trevjones

04/19/2017, 3:24 PM
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

kevinmost

04/19/2017, 3:25 PM
it's weird because finding the views by ID does work, the synthetic views are just null apparently
t

trevjones

04/19/2017, 3:33 PM
are you doing like
activity.some_view_id
or what are the specifics?
k

kevinmost

04/19/2017, 3:41 PM
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

trevjones

04/19/2017, 3:43 PM
what import are you using for the synthetics?
k

kevinmost

04/25/2017, 8:39 PM
@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 😕