Unit test Android, getString from resource
Untested: would it work to use the below, and probably targetContext?
android {
testOptions {
unitTests {
includeAndroidResources = true
}
}
}
If you are using Context
only for obtaining String
resource, I would go by mocking only getResources().getString()
part like this (see JUnit4 notation):
@RunWith(MockitoJUnitRunner.class)
public class AlertaPOJOTest {
@Mock
Context mMockContext;
@Test
public void setDiaByTextView() {
String texto = "L,M,X,J,V,S,D";
when(mMockContext.getString(R.string.sInicialLunes))
.thenReturn(INITIAL_LUNES);
alertaPOJO.setDiaByText(texto);
assertEquals(alertaPOJO.getIsSelectedArray()[0], true);
assertEquals(alertaPOJO.getI_idiaSeleccionado()[0], 1);
}
}
There are many reasons to stay with JVM tests, most important one, they are running quicker.