SuperNotCalledException running unit test
I am trying to run this Android unit test, following this tutorial ::
http://developer.android.com/resources/tutorials/testing/helloandroid_test.html
and in doing so get a SuperNotCalledException
Here's the test class code ::
package com.example.helloandroid2.test;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView开发者_高级运维;
import com.example.helloandroid2.HelloAndroid2Activity;
public class HelloAndroid2Test extends ActivityInstrumentationTestCase2<HelloAndroid2Activity>
{
private HelloAndroid2Activity mActivity;
private TextView mView;
private String resourceString;
public HelloAndroid2Test()
{
super("com.example.helloandroid2", HelloAndroid2Activity.class);
}
@Override
protected void setUp() throws Exception
{
super.setUp();
mActivity = this.getActivity();
mView = (TextView) mActivity.findViewById(com.example.helloandroid2.R.id.textview);
resourceString = mActivity.getString(com.example.helloandroid2.R.string.hello);
}
public void testPreconditions()
{
assertNotNull(mView);
}
public void testText()
{
assertEquals(resourceString,(String)mView.getText());
}
}
The class I'm actually testing ::
package com.example.helloandroid2;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
}
}
I've set the project API levels at 2_3_1 and am using an avd set at the same. Am running Eclipse with ADT on Windows Vista.
All wisdom greatfully recieved. Thanks in advance.
Chris
Your onCreate()
method in HelloAndroid2Activity
needs to call super.onCreate(savedInstanceState);
public class HelloAndroid2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
精彩评论