Hi.
I’m beginner of unit testing and I need to make test cases and report test
coverage. I’m writing unit testing code for my application with
ActivityUnitTestCase. Everything works perfect until I have to test my
TabActivity. As described in reference, in configuration of
ActivityUnitTestCase, startActivity may be called but will not do anything.
TabActivity starts activities that will be rendered as tab contents. As
TabHost’s startActivity() do nothing, TabHost’s addTab() makes
NullPointerException when I called startActivity() from setUp() of
ActivityUnitTestCase. Here’s code I used for the test and the exception.
Other activities rather than tab activity works fine with this code.
public class ProductInfoActivityTest extends
ActivityUnitTestCase<ProductInfoActivity> {
private ProductInfoActivity activity;
@Override
protected void setUp() throws Exception {
super.setUp();
startActivity(new Intent(), null, null);
activity = getActivity();
}
...
java.lang.NullPointerException
at
android.app.LocalActivityManager.startActivity(LocalActivityManager.java:277)
at
android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
at android.widget.TabHost.setCurrentTab(TabHost.java:326)
at android.widget.TabHost.addTab(TabHost.java:216)
at com.tvstorm.app.ProductInfoActivity.onCreate(ProductInfoActivity.java:40)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at
android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:159)
at
com.tvstorm.app.test.ProductInfoActivityTest.setUp(ProductInfoActivityTest.java:19)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
If I use ActivityInstrumentationTestCase2 instead, some test cases are
covered. But, it doesn’t support mock context injection which I need to
make isolated environment for testing.
Is there any way to unit test TabActivity with mock context?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en