android studio 找不到roundicon,[求助] 在 AndroidStudio 中使用 Robotium 出错,找不到测试 class...

orz 初衷很简单,本是想在写个自动化脚本用 intent 直接调用特定的 activity,因为权限问题,只能用 Robotium 这类的框架,但是后来发现用在 Android Studio 中用 Robotium 简直到处碰壁。求救。

测试类是:com.aabbcc.robtest.ExampleInstrumentedTest

测试目标 apk:com.aabbcc.client.stg

测试脚本所在的包名:com.aabbcc.robtest

工程的结构如下:

54e4234cb710b3e07016061a981c6b5f.png

manifests 设置

package="com.aabbcc.robtest">

android:name="android.test.InstrumentationTestRunner"

android:targetPackage="com.aabbcc.client.stg">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

gradle 设置:

apply plugin: 'com.android.application'

android {

signingConfigs {

config {

keyAlias 'androiddebugkey'

keyPassword 'android'

storeFile file('/Users/zanghuizhi/Downloads/tttttt/android.keystore')

storePassword 'android'

}

}

compileSdkVersion 25

buildToolsVersion '25.0.0'

defaultConfig {

applicationId "com.aabbcc.robtest"

minSdkVersion 19

targetSdkVersion 25

versionCode 1

versionName "1.0"

testInstrumentationRunner "android.test.InstrumentationTestRunner"

}

buildTypes {

release {

minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

debug {

signingConfig signingConfigs.config

}

}

}

dependencies {

compile fileTree(include: ['*.jar'], dir: 'libs')

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1', {

exclude group: 'com.android.support', module: 'support-annotations'

})

compile 'com.android.support:appcompat-v7:25.+'

testCompile 'junit:junit:4.12'

androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.3.1'

}

测试代码

package com.aabbcc.robtest;

import android.content.Context;

import android.support.test.InstrumentationRegistry;

import android.support.test.runner.AndroidJUnit4;

import android.test.ActivityInstrumentationTestCase2;

import com.robotium.solo.Solo;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**

* Instrumentation test, which will execute on an Android device.

*

* @see Testing documentation

*/

public class ExampleInstrumentedTest extends ActivityInstrumentationTestCase2 {

private Solo solo;

private static String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.aabbcc.client.module.mologin.activity.SplashActivity";

private static String TARGET_PACKAGE_ID = "com.aabbcc.client.stg";

public ExampleInstrumentedTest() throws ClassNotFoundException {

super(TARGET_PACKAGE_ID, Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME));

}

@Before

public void setUp() throws Exception {

solo = new Solo(this.getInstrumentation(), this.getActivity());

}

@Test

public void useAppContext() throws Exception {

solo.sleep(5000);

solo.clickLongOnText("生日问候");

solo.sleep(5000);

}

@After

public void tearDown() throws Exception {

solo.finishOpenedActivities();

}

}

直接在 AndroidStudio 中直接运行测试,会发现很诡异的用的是 AndroidJUnitRunner,然后找不到 instrumentation info

07/05 17:42:02: Launching ExampleInstrumentedT...

$adb push /Users/zanghuizhi/AndroidStudioProjects/RobTest/app/build/outputs/apk/app-debug.apk /data/local/tmp/com.aabbcc.robtest

$adb shell pm install -r "/data/local/tmp/com.aabbcc.robtest"

Success

$adb push /Users/zanghuizhi/AndroidStudioProjects/RobTest/app/build/outputs/apk/app-debug-androidTest.apk /data/local/tmp/com.aabbcc.robtest.test

$adb shell pm install -r "/data/local/tmp/com.aabbcc.robtest.test"

Success

Running tests

$adb shell am instrument -w -r -e debug false -e class com.aabbcc.robtest.ExampleInstrumentedTest com.aabbcc.robtest.test/android.support.test.runner.AndroidJUnitRunner

Client not ready yet..

Started running tests

Test running failed: Unable to find instrumentation info for: ComponentInfo{com.aabbcc.robtest.test/android.support.test.runner.AndroidJUnitRunner}

Empty testsuite.

用命令执行测试,出现 process crashed

adb shell am instrument -w -r -e debug false -e class com.aabbcc.robtest.ExampleInstrumentedTest com.aabbcc.robtest/android.test.InstrumentationTestRunner

INSTRUMENTATION_RESULT: shortMsg=Process crashed.

INSTRUMENTATION_CODE: 0

看 logcat 的日志发现是

07-05 17:05:24.139 16586 16586 E AndroidRuntime: FATAL EXCEPTION: main

07-05 17:05:24.139 16586 16586 E AndroidRuntime: Process: com.aabbcc.client.stg, PID: 16586

07-05 17:05:24.139 16586 16586 E AndroidRuntime: java.lang.RuntimeException: Exception thrown inonCreate() of ComponentInfo{com.aabbcc.robtest/android.test.InstrumentationTestRunner}: java.lang.RuntimeException: Could not find testclass. Class: com.aabbcc.robtest.ExampleInstrumentedTest

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5427)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.app.ActivityThread.-wrap2(ActivityThread.java)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1568)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.os.Looper.loop(Looper.java:160)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6200)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: Caused by: java.lang.RuntimeException: Could not find testclass. Class: com.aabbcc.robtest.ExampleInstrumentedTest

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.test.AndroidTestRunner.runFailed(AndroidTestRunner.java:262)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.test.AndroidTestRunner.loadTestClass(AndroidTestRunner.java:96)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:57)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:78)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:449)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:430)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:376)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5424)

07-05 17:05:24.139 16586 16586 E AndroidRuntime: ... 8 more

07-05 17:05:24.164 16586 16586 I Process : Sending signal. PID: 16586 SIG: 9

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值