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:
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!
If your tests are in the androidTest
directory then you need
androidTestImplementation 'com.google.truth:truth:0.43'
but if your tests are in the test
directory then you need
testImplementation 'com.google.truth:truth:0.43'
Blockquote
If your use kotlin use
testImplementation 'androidx.test.ext:truth:1.3.0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With