Reputation: 1952
I have class that reads properties from assets
directory. Construtor of this class have Context. I want to write test for this class but I really don't don't how to get context in Android Tests.
public class PropertyLoader {
private Context context;
private Properties properties;
public PropertyLoader(Context context) {
this.context = context;
properties = new Properties();
}
public Properties getProperties(String FileName) {
...
}
}
Test class
public class PropertyLoaderTest extends InstrumentationTestCase {
@Test
public void testSimple() {
Context context = getInstrumentation().getContext();
PropertyLoader propertyLoader = new PropertyLoader(context);
}
}
I get following exception
junit.framework.AssertionFailedError: Exception in constructor: testSimple (java.lang.RuntimeException: Stub!
Upvotes: 0
Views: 122
Reputation: 685
TestCase with context ( Test will run on device or emulator ) -http://developer.android.com/reference/android/test/AndroidTestCase.html
Upvotes: 1
Reputation: 152817
Run your tests on an Android emulator or a device.
The android.jar you're using on your desktop doesn't have anything implemented. All methods there throw the RuntimeException: Stub!
.
Alternatively, remove all Android dependencies from the code so that you can run your tests without importing android.jar.
Upvotes: 1