3

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!!

Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
Rgfvfk Iff
  • 1,549
  • 2
  • 23
  • 47

1 Answers1

3

Add in the gradel unit test option for resource to access compiled resources during testing

testOptions {
    unitTests {
        includeAndroidResources = true
    }
}

RoboElectric docs

Irfan Ul Haq
  • 1,065
  • 1
  • 11
  • 19