gpt4 book ai didi

安卓-InstrumentationTestRunner

转载 作者:可可西里 更新时间:2023-11-01 18:45:39 26 4
gpt4 key购买 nike

我是 Android 的新手,对 Java 有点生疏,来自 .NET 背景。我正在为在 Android 上运行的移动应用程序开发一些测试自动化。

目前,我只是使用 Android 调试桥通过命令行启动测试,但是当我尝试运行任何测试时出现错误:

首先,这是我收到的错误:

junit.framework.TestSuite$1: Failure in warning: junit.framework.AssertionFailedError: No tests found in com.myapp.test.UITests 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)

我正在使用此 adb 命令尝试启动测试(在 Root设备上):

adb shell am instrument -e class com.myapp.test.UITests -w com.myapp.test/android.test.InstrumentationTestRunner

最后,这是我尝试从中运行测试的类:

package com.myapp.test;

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import com.jayway.android.robotium.solo.Solo;
import junit.framework.Assert;

@SuppressWarnings("unchecked")
public class UITests extends ActivityInstrumentationTestCase2
{
private static final String TARGET_PACKAGE_ID = "com.myapp.main";
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.myapp.main.activities.MainActivity";
private static Class<?> launcherActivityClass;

private Solo solo;
private Activity activity;

static
{
try
{
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
}
catch(ClassNotFoundException e)
{
throw new RuntimeException(e);
}
}

public UITests() throws ClassNotFoundException
{
super(TARGET_PACKAGE_ID, launcherActivityClass);
}

@Override
protected void setUp()
{
activity = getActivity();
solo = new Solo(getInstrumentation(), activity);

}

@Override
public void runTest() throws Throwable
{
// Simple Test
Assert.assertTrue(solo.searchText("Welcome"));
}

@Override
protected void tearDown() throws Exception
{
try
{
solo.finalize();
}
catch(Throwable e)
{
}
getActivity().finish();
super.tearDown();
}

}

我一定做错了什么,但我不确定是什么。我的代码基于 example我在 Robotium 网站上找到的。

如果有人能指出我的错误,我将不胜感激。

更新 - 根据要求添加 list 文件

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.test"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="3" />

<application android:icon="@drawable/icon" android:label="@string/ws_app_name">
<uses-library android:name="android.test.runner" />
</application>

<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.myapp.main"
android:label="My App Tests"/>
</manifest>

最佳答案

我设法解决了这个问题,我没有意识到每个测试函数名称都必须按照概述的 'test' 开头 here .

关于安卓-InstrumentationTestRunner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8770694/

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