android application test failed with error "Unable to start the UTP test results listener gRPC server"

Viewed 276

I start learing android application testing
I add google library to gradle. this is libraries:

  • testImplementation "com.google.truth:truth:1.0.1"

  • androidTestImplementation "com.google.truth:truth:1.0.1"

I write a function that checks that string(parameter) is equals to specific string in resource file. this is the code:

class ResourceComparer {
   fun isEqual(context: Context, resId: Int, string: String): Boolean {
    return context.getString(resId) == string
   }
}  

then i set it's Test function in androidTest directory like this:

class ResourceComparerTest {
private lateinit var resourceComparer :ResourceComparer

@Before
fun setUp(){
    resourceComparer = ResourceComparer()
}
@Test
fun stringResourceSameAsGivenString_returnsTrue() {
    val context = ApplicationProvider.getApplicationContext<Context>()
    val result = resourceComparer.isEqual(context, resId = R.string.app_name, "PracticeTesting")
    assertThat(result).isTrue()
}
@Test
fun stringResourceDifferentAsGivenString_returnsFalse() {
    val context = ApplicationProvider.getApplicationContext<Context>()
    val result = resourceComparer.isEqual(context, resId = R.string.app_name, "Practice")
    assertThat(result).isFalse()
   }
}

but when it failed with an error when i run this. this is the error:

Execution failed for task ':app:connectedDebugAndroidTest'.

java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Unable to start the UTP test results listener gRPC server.

I also used project's TestFunction too but to no avail

UPDATE

i changed gradle plugin version to 7.0.3 and gradle version to 7.0.2 ,now it's ok and error is gone

but why?? can anyone explain why this happens?

0 Answers
Related