jeudi 13 juin 2019

SetStaticField BuildConfig

I try to change the value of a static field in the BuildConfig class with robolectric in version 4.3. In debugging mode, if I access the field multiple times, the value change for the expecting result. But if you start the test it fails. The field holds its old value.

Did I missed something ? Thank you.

@RunWith(RobolectricTestRunner.class)
public class MyTestClass {
        @Test
    public void test() {
        setStaticField(BuildConfig.class, "VERSION_NAME", "aVersion");
        assertThat(BuildConfig.VERSION_NAME).isEqualTo("aVersion"); // Fails, the field holds its old value
    }
}   

Aucun commentaire:

Enregistrer un commentaire