gpt4 book ai didi

java - 无法实例化检测 ComponentInfo

转载 作者:行者123 更新时间:2023-11-30 04:13:41 27 4
gpt4 key购买 nike

我正在尝试为 Android 设置 JUnit 测试并且我有 list 等设置但我不断收到此错误:

java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo {com.example.Android/android.test.InstrumentationTestRunner}: java.lang.ClassNotFoundException: android.test.InstrumentationTestRunner in loader dalvik.system.PathClassLoader[/data/app/com.example.Android-1.apk:/data/app/com.example.Android-1.apk]

测试类:

  public class ConnectionToSiteTest extends AndroidTestCase{
private final String emailUsername = "testUser@gmail.com";
private final String password = "test";
private final String features = "222222";
private String commands;

public void testCommandReturn(){
requestToSite();

assertEquals("222222", commands);
}

private void requestToSite(){
try {
// Create params for connection including 3sec timeout
// on connection and 5sec timeout on socket
HttpParams httpParams = new BasicHttpParams();
int timeoutConnection = 3000;
int timeoutSocket = 5000;

// Set the timeouts
HttpConnectionParams.setConnectionTimeout(httpParams,
timeoutConnection);
HttpConnectionParams.setSoTimeout(httpParams, timeoutSocket);
HttpClient httpClient = new DefaultHttpClient(httpParams);

// Create the data entities
HttpPost post = new HttpPost("http://example.com/AndroidCommands");
HttpResponse response;

// Set POST data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
2);
nameValuePairs.add(new BasicNameValuePair("emailUsername",
emailUsername));
nameValuePairs.add(new BasicNameValuePair("password",
password));
nameValuePairs.add(new BasicNameValuePair("features",
features));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Query the server and store the user's ID
response = httpClient.execute(post);

// Grabs the command string from response headers and processes them
commands = (String) response.getHeaders("commands")[0].getValue();

} catch (UnsupportedEncodingException e) {
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
}
}

AndroidManifest.xml:

<uses-library android:name="android.test.runner" />
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="edu.neumont.MillerK.Android" android:label="Tests for My App" />
<activity
android:name="com.example.Android.ConnectionToSiteTest">
</activity>

测试套件类:

    public class AllTests extends TestSuite {
public static Test suite() {
return new TestSuiteBuilder(AllTests.class).includeAllPackagesUnderHere().build();
}
}

我一直试图在某处找到相同的异常,但它已被修复,但没有找到任何东西。

最佳答案

您确定测试在正确的 Android 测试项目中吗?您可以在 Eclipse 中添加一个,方法是右键单击您的项目 -> Android 工具 -> 添加 Android 测试项目。您所有的测试都应该放在该项目中。

关于java - 无法实例化检测 ComponentInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10408025/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com