Android 无法将测试用例添加到TestSuite
我已经编写了Runner类来执行一个测试套件,但在套件构建过程中,我不断得到java.lang.RuntimeException:Exception。方法名不能为nullAndroid 无法将测试用例添加到TestSuite,android,junit,Android,Junit,我已经编写了Runner类来执行一个测试套件,但在套件构建过程中,我不断得到java.lang.RuntimeException:Exception。方法名不能为null import junit.framework.TestSuite; import android.test.InstrumentationTestRunner; import android.test.InstrumentationTestSuite; public class Runner extends Instrume
import junit.framework.TestSuite;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
public class Runner extends InstrumentationTestRunner {
public Runner() {
super();
}
@Override
public TestSuite getAllTests() {
InstrumentationTestSuite suite = new InstrumentationTestSuite(this);
suite.addTest(new AndroidTest());
return suite;
}
@Override
public ClassLoader getLoader() {
return Runner.class.getClassLoader();
}
}
我的测试用例文件
import junit.framework.Assert;
import android.test.ActivityTestCase;
public class AndroidTest extends AndroidTestCase{
@Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
}
String nuber;
public AndroidTest(String number1) {
System.out.println("paramertized");
this.nuber=number1;
}
public AndroidTest() {
super();
System.out.println("default");
}
public void testSomething() throws Throwable {
System.out.println(nuber);
Assert.assertTrue(1 + 1 == 2);
}
public void testSomethingElse() throws Throwable {
Assert.assertTrue(1 + 1 == 3);
}
}
我的文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.co.rakuten.sdt.sampleapp.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />
<uses-sdk android:minSdkVersion="9" />
<instrumentation
android:name="com.sampleapp.test.Runner"
android:targetPackage="com.sampleapp" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>
好的,我可以重现你的问题 通过删除
public AndroidTest(String)
构造函数并为字符串变量number设置一个值,我可以运行测试
String nuber ="";
/*
public AndroidTest(String number1) {
super();
System.out.println("paramertized");
this.nuber=number1;
}
*/
public AndroidTest() {
super();
System.out.println("default");
}
Hmm,作为一个测试,尝试删除参数化构造函数。非常确定是参数化构造函数让您感到悲伤。我也删除了参数化构造函数,即使我无法运行套件。同样的问题是您所做的任何其他更改(在清单或其他地方)。初始化字符串编号=“”或您收到空指针异常。感谢您的响应,但在您告诉我所有更改后,我仍然遇到相同的问题。
String nuber ="";
/*
public AndroidTest(String number1) {
super();
System.out.println("paramertized");
this.nuber=number1;
}
*/
public AndroidTest() {
super();
System.out.println("default");
}