I am trying to include the Google Truth framework in my project for testing. I followed the documentation on how to get the project setup.
This is from my app's build.gradle file:
dependencies {
...
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
androidTestImplementation 'androidx.test.ext:truth:1.1.0'
androidTestImplementation 'com.google.truth:truth:0.43'
}
The syncing process completes successfully.
Then I attempt to run a local unit test for example:
import org.junit.Test
import com.google.common.truth.Truth.*
class CustomExampleUnitTest {
@Test
fun testBlank_isCorrect() {
assertThat("".isBlank()).isTrue()
}
}
I get a Kotlin compiler error: Unresolved reference: truth
There are a couple of things to note:
- When I attempt to use a method related to Truth by just starting to type, there is no suggestions for any of those methods. This is without manually adding the import statement, but Android Studio has always done that automatically when I choose the appropriate method from the suggested ones, so this was the first odd things I noticed.
- When the above mentioned did not work, I manually did the import and as I was typing what to import, I did get suggestions for com.google.common.truth.Truth... which showed me that at least the jar file was somewhere to be found. After this manual import, the Android Studio then started suggesting methods from Truth as I expected before.
So after going through the steps above, I tried to run the test and I still get the unresolved issue.
Could anyone please try to shed some light on this? Has anyone encountered this. I would be really grateful for any kind of help!
import com.google.common.truth.Truth.*
in addition to that. No auto suggestions otherwise. Find latest truth extension version on developer.android.com/jetpack/androidx/releases/test – Pleuron