google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.45k stars 2.02k forks source link

Unresolved reference for testing activity and fragments with hilt #2540

Closed SepidehAkbarinezhad closed 3 years ago

SepidehAkbarinezhad commented 3 years ago

as I get from documents for testing activity and fragment with hilt there are two dependencies to add to gradle , and I did :

def fragment_version = "1.3.1" debugImplementation "androidx.fragment:fragment-testing:$fragment_version" def test_version = "1.2.0" androidTestImplementation "androidx.test:core-ktx:$test_version"

but I can't access to any methods of these two libraries . when I want to use launchFragmentInHiltContainer found( https://github.com/android/architecture-samples/blob/dev-hilt/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/HiltExt.kt), the stuff relates to FragmentScenario are red .

I have an error of Unresolved reference for the line below: import androidx.fragment.app.testing.FragmentScenario.EmptyFragmentActivity

and when it comes to test activity I have the same problem ,and there is no reference for : import androidx.test.core.app.launchActivity

danysantiago commented 3 years ago

You are liking missing a few more dependencies.

Try also adding androidx.test:core and taking a look at some of the other test dependencies declared in the blueprint: https://github.com/android/architecture-samples/blob/dev-hilt/app/build.gradle#L147

SepidehAkbarinezhad commented 3 years ago

You are liking missing a few more dependencies.

Try also adding androidx.test:core and taking a look at some of the other test dependencies declared in the blueprint: https://github.com/android/architecture-samples/blob/dev-hilt/app/build.gradle#L147

according to some tutorials which i've watched for testing , I only added :

implementation "androidx.test:core:$androidXTestCoreVersion"

but as you mentioned I also added :

testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion" and androidTestImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"

and it solved my problem . tnx