I start with Mockito for Android without Unit Test headphones. The part I want to test is in the backend, which depends on the context. I tried to mock the context, but I get null when I run the test.
The mocking context seen in this example does not show me how it is taunted: https://developer.android.com/training/testing/unit-testing/local-unit-tests.html#setup
The example from the link mentioned above ( https://github.com/googlesamples/android-testing/tree/master/unit/BasicSample ) does not have an example of how the context is being mocked.
So, I lost a little.
In my gradle dependencies, I have the following:
testCompile 'junit:junit:4.12' androidTestCompile 'com.android.support.test:runner:0.4' androidTestCompile 'com.android.support.test:rules:0.4' androidTestCompile 'com.android.support:support-annotations:23.0.1' testCompile 'org.mockito:mockito-core:1.10.19' androidTestCompile('com.android.support.test:testing-support-lib:0.+')
Code snippet:
@RunWith(MockitoJUnitRunner.cass) public static Test { @Mock Context mContext; RequestQueue mQueue; @Test public void getCategories(){ final String SERVER = "http://{...}/categories"; mContext = mock(Context.class); int size = 20; when(mContext.getResources().getInteger(R.integer.cache_size)).thenReturn(size); mQueue = VolleyUtil.newRequestQueue(mContext, null, size); final Response.Listener<String> listener = new Response.Listener(){
}
My zero exception occurs when:
final PackageInfo queue = context.getPackageManager().getPackageInfo(network, 0);
Suppose you mimic a package manager or application instance?
source share