I'm currently trying to write some tests for an Android app I have with no UI (simple background service). My Android service basically calls another class that takes care of most of the work. It is this class that I want to test, but in it I use stuff like:
Is there a way to mock these values or change their default values during the tests?
For Android we use a library called Mockito
A simple way to do what you want would be:
// create mock YourBackgroundService test = Mockito.mock(YourBackgroundService.class); // define return value for method getSerial() when(test.getSerial()).thenReturn("42UNIV"); // use mock in test.... assertEquals(test.getSerial(), "42UNIV");