InstrumentalTests: Unresolved reference: create
See original GitHub issue- I have searched existing issues and this is not a duplicate
Version
ext {
screenshotTestVersion = '0.6.0'
kotlinVersion = '1.2.41'
litho = '0.15.0'
}
Issues and Steps to Reproduce
I create test according to https://github.com/facebook/screenshot-tests-for-android/blob/master/sample/src/androidTest/java/com/facebook/testing/screenshot/sample/ExampleScreenshotTest.java
e: ../app/src/androidTest/java/kt/test/instrumental/screenshots/specs/TestLandingSpec.kt: (26, 33): Unresolved reference: create
:kt-app:compileDevStagingAndroidTestKotlin FAILED
Link to Code
Spec
@LayoutSpec
object LandingSpec {
@OnCreateLayout
fun onCreateLayout(context: ComponentContext) : Component {
return Row
.create(context)
.backgroundRes(R.color.color_white)
.widthPercent(100f)
.heightPercent(100f)
.child(
Image.create(context)
.drawableRes(R.drawable.ic_splash_screen)
)
.justifyContent(YogaJustify.CENTER)
.alignItems(YogaAlign.CENTER)
.build()
}
}
Test
class TestLandingSpec {
@Test
fun testLanding() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val li = LayoutInflater.from(context)
val lithoView = li.inflate(R.layout.test_litho_view, null, false) as LithoView
val component = Landing.create(lithoView.componentContext).build()
lithoView.setComponent(component)
ViewHelpers.setupView(lithoView).setExactWidthDp(360).setExactHeightDp(640).layout()
Screenshot.snap(lithoView).record()
}
}
But it works when:
- i create component without generated code
val component = LandingSpec.onCreateLayout(lithoView.componentContext)
- i create screenshot of whole activity with this component
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Unresolved reference: testing - android - Stack Overflow
InstrumentationRegistry within the test directory for a JUnit test. The error is 'Unresolved reference: test'. Here is the solution to my issue ...
Read more >Android Studio is reporting Unresolved reference, in wrong ...
Android Studio is reporting Unresolved reference, in wrong test scope. It seems, that Android Studio is mixing InstrumentationTest and UnitTest dependencies ...
Read more >MPP: Unresolved reference during ... - YouTrack
To create problem, perform these steps: In IDEA, use new project wizard to create multiplatform mobile application for android and ios. Any name,...
Read more >Learning unit testing on Android: Unresolved reference - Reddit
Hi, I'm learning unit testing on Android. I picked this tutorial as starting point. Now I have this unit test: import org.junit.Assert.
Read more >Getting "unresolved reference" error when the reference can ...
I am developing and Android app using Android Studio. While trying to run some JUnit tests for my database, I am getting multiple ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay I managed to find a solution for your case! There seems to be a bug somewhere (not sure where though).
Solution is consisted of two parts:
You need to add
kaptAndroidTest 'com.facebook.litho:litho-processor:0.15.0'
so that it can invoke thekapt
AP forandroidTest
related tasks as well!Regarding the issue I mentioned above, it seems that generated files are not properly copied over to
kapt
generated sources folder.Add the following on your app’s module
build.gradle
:What this does, is before running
compileDebugAndroidTestKotlin
task it copies the generated.java
files over to theandroidTest
folder, in order for the test to be able to find those classes on runtime.Edit 1: Seems that this won’t work properly when combined with
clean
, so we modify thecopyTestClasses
task in order to forceconnectedDebugAndroidTestKotlin
to wait for the classes to be copied, before executing.Hey @just-kip seems that indeed
./gradlew clean connectedDebugAndroidTest
does not work properly. I have modified thecopyTestClasses
task in order to make it run always afterkaptDebugAndroidTestKotlin
and sincecompileDebugAndroidTestKotlin
depends on it, it waits until it copies those classes over, before running.Here is the modified task: