I am trying to run the simple unit test by following the example here:
https://developer.android.com/training/testing/unit-testing/local-unit-tests
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Test;
import static com.google.common.truth.Truth.assertThat;
public class UnitTestSampleJava {
private static final String FAKE_STRING = "HELLO_WORLD";
private Context context = ApplicationProvider.getApplicationContext();
@Test
public void readStringFromContext_LocalizedString() {
// Given a Context object retrieved from Robolectric...
ClassUnderTest myObjectUnderTest = new ClassUnderTest(context);
// ...when the string is returned from the object under test...
String result = myObjectUnderTest.getHelloWorldString();
// ...then the result should be the expected one.
assertThat(result).isEqualTo(FAKE_STRING);
}
}
I have a brand new project and I set the gradle files as specified, then I created a test with this line:
private Context context = ApplicationProvider.getApplicationContext();
and I get an exception on that line number stating:
java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.
However, this was listed in the docs as a local unit test and not an instrumented test.