Rgfvfk Iff
Rgfvfk Iff

Reputation: 1609

Robolectric test case for Kotlin code

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

Upvotes: 3

Views: 5639

Answers (1)

Irfan Ul Haq
Irfan Ul Haq

Reputation: 1155

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

testOptions {
    unitTests {
        includeAndroidResources = true
    }
}

RoboElectric docs

Upvotes: 3

Related Questions