2

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,740
  • 7
  • 24
  • 48
Rgfvfk Iff
  • 1,389
  • 1
  • 20
  • 43

1 Answers1

2

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

testOptions {
    unitTests {
        includeAndroidResources = true
    }
}

RoboElectric docs

Irfan Ul Haq
  • 965
  • 1
  • 10
  • 19