这是一些示例代码,似乎对我不起作用.
public class CropImageTest extends ActivityInstrumentationTestCase2<CropImage> {
private Instrumentation mInstrumentation;
private CropImage mActivity;
private String filename = "/mnt/sdcard/DCIM/Camera/2011-05-12 09.22.56.jpg";
private int aspectX = 1;
private int aspectY = 1;
private boolean scale = true;
public CropImageTest() {
super("hk.com.novare.android.cropimage", CropImage.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
this.mInstrumentation = getInstrumentation();
Intent i = new Intent(mInstrumentation.getContext(), CropImage.class);
i.putExtra("image-path", filename);
i.putExtra("aspectY", aspectY);
i.putExtra("aspectX", aspectX);
i.putExtra("scale", scale);
setActivityIntent(i);
mActivity = this.getActivity();
}
public void testExtras() {
String str = "";
str = mActivity.getIntent().getStringExtra("image-path");
assertEquals(filename, str);
}
}
遇到错误:
Unable to resolve activity for: Intent ( has Extras )
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="hk.com.novare.android.cropimage.tests">
<uses-sdk android:minSdkVersion="8"/>
<instrumentation
android:targetPackage="hk.com.novare.android.cropimage"
android:name="android.test.InstrumentationTestRunner"/>
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<uses-library android:name="android.test.runner"/>
</application>
</manifest>
即使设置了构造函数-> ;,我也遇到了以上错误. super的字符串(一个包)与我在此测试项目的manifest.xml中指示的字符串相同.
请帮我.
解决方法:
我想你要做的就是使用
Intent i = new Intent();
参见,例如,关于this thread的答案.