jxs1211 / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

Context not initialized with ProviderTestCase2 (NullPointerException) #148

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create a SQLiteOpenHelper implementation
2. Create a ContentProvider using it
3. Create a ProviderTestCase2 implementation to test the provider
4. Use AndroidJUnitRunner and JUnit4-style tests to run the test case

What is the expected output? What do you see instead?

The same test case works fine with JUnit3 and gives proper results (test 
passed/failed).
When configured for JUnit4, I get a java.lang.NullPointerException on the 
context passed to my SQLiteOpenHelper's constructor which is automatically 
called during ProviderTestCase2#setUp().

Full trace :

java.lang.NullPointerException
at 
android.test.RenamingDelegatingContext.openOrCreateDatabase(RenamingDelegatingCo
ntext.java:157)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:235)
at 
android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java
:224)
at 
android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.ja
va:164)
at com.foobar.bbb.FooProvider.insert(FooProvider.java:41)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:213)
at android.content.ContentResolver.insert(ContentResolver.java:914)
at com.foobar.bbb.FooProviderTestCase.testDummy(FooProviderTestCase.java:49)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java
:45)
at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:
15)
at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:4
2)
at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20
)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68
)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47
)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
at 
android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
at 
android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:2
28)
at 
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)

What version of the product are you using? On what operating system?

com.android.support.test.espresso:espresso-core:2.1
Android Studio 1.2
JDK 1.8.0
Fedora 20

Please provide any additional information below.

I am joining a sample Android Studio project which reproduces the problem. To 
switch between Junit3/4 just comment/uncomment marked lines in 
FooProviderTestCase.java and app/build.gradle

Original issue reported on code.google.com by thomas.r...@gmail.com on 1 May 2015 at 5:27

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by nkors...@google.com on 5 May 2015 at 5:27