Shot icon indicating copy to clipboard operation
Shot copied to clipboard

Add androidx.compose.ui:ui-test-manifest:$composeVersion as part of the shot core module dependencies

Open sanginovs opened this issue 3 years ago • 2 comments

HI @pedrovgs I am trying to make Shot work with compose in my project. I followed shot-consumer-compose and have exact same dependencies but when I run my compose UI test, i am getting this error. I tried to play with dependencies but still no success. Any idea what may be causing this?

java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.myapp.debug.test/androidx.activity.ComponentActivity }
	at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:387)
	at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:416)
	at androidx.test.core.app.ActivityScenario.launchInternal(ActivityScenario.java:265)
	at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:195)
	at androidx.test.ext.junit.rules.ActivityScenarioRule.lambda$new$0$ActivityScenarioRule(ActivityScenarioRule.java:70)
	at androidx.test.ext.junit.rules.ActivityScenarioRule$$Lambda$0.get(Unknown Source:2)
	at androidx.test.ext.junit.rules.ActivityScenarioRule.before(ActivityScenarioRule.java:103)
	at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
	at androidx.compose.ui.test.junit4.AndroidComposeTestRule$AndroidComposeStatement.evaluateInner(AndroidComposeTestRule.android.kt:357)
	at androidx.compose.ui.test.junit4.AndroidComposeTestRule$AndroidComposeStatement.evaluate(AndroidComposeTestRule.android.kt:346)
	at androidx.compose.ui.test.junit4.android.EspressoLink$getStatementFor$1.evaluate(EspressoLink.android.kt:63)
	at androidx.compose.ui.test.junit4.IdlingResourceRegistry$getStatementFor$1.evaluate(IdlingResourceRegistry.jvm.kt:160)
	at androidx.compose.ui.test.junit4.android.ComposeRootRegistry$getStatementFor$1.evaluate(ComposeRootRegistry.android.kt:150)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
	at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)

My app/build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'shot'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.xyz.myapp"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "com.karumi.shot.ShotTestRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
        useIR = true
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion composeVersion
        kotlinCompilerVersion kotlinVersion
    }
    buildTypes {

        debug {
            applicationIdSuffix ".debug"
            debuggable true
        }
    }

    packagingOptions {
        exclude "META-INF/*"
    }
}

shot {
    tolerance = 0.6 
    runInstrumentation = Boolean.valueOf(getArgument("runInstrumentation", "true"))
}

dependencies {
   
    implementation project(':libraries:my-library')
    implementation project(':libraries:my-library')
    implementation project(':features:my-library')
   
    implementation "androidx.core:core-ktx:1.3.2"
    implementation "androidx.appcompat:appcompat:1.2.0"
    implementation "com.google.android.material:material:1.3.0"
    implementation "androidx.compose.ui:ui:$composeVersion"
    implementation "androidx.compose.material:material:$composeVersion"
    implementation "androidx.compose.ui:ui-tooling:$composeVersion"
    implementation "androidx.activity:activity-compose:1.3.0-alpha05"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"

    testImplementation "junit:junit:4.13.1"

    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$composeVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
    androidTestImplementation "androidx.test:core-ktx:1.3.0"
    androidTestImplementation "androidx.test:core:1.3.0"
    androidTestImplementation "androidx.test:runner:1.3.0"
    androidTestImplementation "androidx.test.ext:junit:1.1.2"
    androidTestImplementation "androidx.test.ext:junit-ktx:1.1.2"
}

My test file:

import androidx.compose.ui.test.junit4.createComposeRule
...

class SomeTest : ScreenshotTest {

    @get:Rule
    val composeRule = createComposeRule()

    @Test
    fun rendersTheDefaultComponent() {
        composeRule.setContent {
            MyAppTheme {
              Surface(color = MaterialTheme.colors.background) {
                  Text(greeting)
              }
        } 
        compareScreenshot(composeTestRule)
        }

sanginovs avatar Dec 23 '21 00:12 sanginovs

adding debugImplementation("androidx.compose.ui:ui-test-manifest:$composeVersion") fixed this issue for me. I wonder why you don't have this dependency on shot-consumer-compose sample?

sanginovs avatar Dec 23 '21 01:12 sanginovs

Because depending on the version you are using the old version can include the activity as part of the artifact and the one you are using doesn't. I'm going to update the issue name to show that the tasks we need to do is to include that dependency.

pedrovgs avatar Dec 23 '21 12:12 pedrovgs