I have a MainActivity written in Kotlin
. I can run the setupActivity
in kotlin
like so:
@RunWith(RobolectricTestRunner::class)
@Config(constants = BuildConfig::class)
class MyActivityTestKotlin {
@Before
public fun setup() {
Robolectric.setupActivity(MainActivity::class.java)
}
}
However, when I write the test in java
, I get the error:
android.content.res.Resources$NotFoundException: String resource ID #0x7f0c001f
Java code:
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class MyActivityTest {
@Before
public void setup() {
setupActivity(MainActivity.class);
}
}
Is it possible to write the tests in java
for such cases?Thanks!!
Add in the gradel unit test option for resource to access compiled resources during testing
testOptions {
unitTests {
includeAndroidResources = true
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.