android– 从IDE运行测试但无法从命令行运行

android– 从IDE运行测试但无法从命令行运行,第1张

概述我写过单元测试,仪器测试和浓缩咖啡测试.我还使用AndroidTestOrchestrator运行它们以获得清晰的应用状态(对于Espresso测试非常重要).当我从AndroidStudio运行这些测试时,一切正常.但是当我尝试使用命令行时,我收到错误,我无法理解.当我尝试:./gradlewconnectedAndroidTesto

我写过单元测试,仪器测试和浓缩咖啡测试.我还使用Android Test orchestrator运行它们以获得清晰的应用状态(对于Espresso测试非常重要).当我从AndroID Studio运行这些测试时,一切正常.但是当我尝试使用命令行时,我收到错误,我无法理解.

当我尝试:

./gradlew connectedAndroIDTest or connectedDeBUGAndroIDTest

我收到:

Instrumentation run Failed due to 'java.lang.IllegalStateException'com.androID.builder.testing.ConnectedDevice > No tests found.[SM-J106H - 6.0.1] Failed No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

当然我所有的测试都是用@Test注释的.

当我尝试

adb shell am instrument -w my.package/androID.test.InstrumentationTestRunner

我收到

INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{mypackage/myCustomrunner}INSTRUMENTATION_STATUS_CODE: -1

我使用CustomTestRunner,但错误保持不变.

当我尝试

 adb shell 'CLAsspATH=$(pm path androID.support.test.services) app_process /  \ androID.support.test.services.shellexecutor.ShellMain am instrument -w -e \ targetInstrumentation  mypackage/myTestRunner \ androID.support.test.orchestrator/.AndroIDTestorchestrator'

然后输出等于:

Time: 0OK (0 tests)

有人可以向我解释我做错了什么吗?我无法理解为什么在命令行中没有任何作用,但在AndroID Studio中一切正常.

/编辑

我的Customrunner:

public final class CustomTestRunner extends AndroIDJUnitRunner {private static final String TAG = "CustomTestRunner";@OverrIDepublic voID onStart() {    try {        TestListener.getInstance().testRunStarted();    } catch (Exception e) {        e.printstacktrace();    }    runOnMainSync(new Runnable() {        @OverrIDe        public voID run() {            Context app = CustomTestRunner.this.getTargetContext().getApplicationContext();            CustomTestRunner.this.disableAnimations(app);        }    });    ActivitylifecycleMonitorRegistry.getInstance().addlifecycleCallback(new ActivitylifecycleCallback() {        @OverrIDe public voID onActivitylifecycleChanged(Activity activity, Stage stage) {            if (stage == Stage.PRE_ON_CREATE) {                activity.getwindow().addFlags(FLAG_disMISS_KEyguard | FLAG_TURN_SCREEN_ON | FLAG_KEEP_SCREEN_ON);            }        }    });    RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() {        @OverrIDe        public Scheduler apply(Scheduler scheduler) throws Exception {            return Schedulers.from(AsyncTask.THREAD_POol_EXECUTOR);        }    });    RxJavaPlugins.setcomputationSchedulerHandler(new Function<Scheduler, Scheduler>() {        @OverrIDe        public Scheduler apply(Scheduler scheduler) throws Exception {            return Schedulers.from(AsyncTask.THREAD_POol_EXECUTOR);        }    });    RxJavaPlugins.setNewThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {        @OverrIDe        public Scheduler apply(Scheduler scheduler) throws Exception {            return Schedulers.from(AsyncTask.THREAD_POol_EXECUTOR);        }    });    super.onStart();}@OverrIDepublic voID finish(int resultCode, Bundle results) {    try {        TestListener.getInstance().testRunFinished();    } catch (Exception e) {        e.printstacktrace();    }    super.finish(resultCode, results);    enableAnimations(getContext());}private voID disableAnimations(Context context) {    int permStatus = context.checkCallingOrSelfPermission(Manifest.permission.SET_ANIMATION_SCALE);    if (permStatus == PackageManager.PERMISSION_GRANTED) {        setSystemAnimationsScale(0.0f);    }}private voID enableAnimations(Context context) {    int permStatus = context.checkCallingOrSelfPermission(Manifest.permission.SET_ANIMATION_SCALE);    if (permStatus == PackageManager.PERMISSION_GRANTED) {        setSystemAnimationsScale(1.0f);    }}private voID setSystemAnimationsScale(float animationScale) {    try {        Class<?> windowManagerStubClazz = Class.forname("androID.vIEw.IWindowManager$Stub");        Method asInterface = windowManagerStubClazz.getDeclaredMethod("asInterface", IBinder.class);        Class<?> serviceManagerClazz = Class.forname("androID.os.ServiceManager");        Method getService = serviceManagerClazz.getDeclaredMethod("getService", String.class);        Class<?> windowManagerClazz = Class.forname("androID.vIEw.IWindowManager");        Method setAnimationScales = windowManagerClazz.getDeclaredMethod("setAnimationScales", float[].class);        Method getAnimationScales = windowManagerClazz.getDeclaredMethod("getAnimationScales");        IBinder windowManagerBinder = (IBinder) getService.invoke(null, "window");        Object windowManagerObj = asInterface.invoke(null, windowManagerBinder);        float[] currentScales = (float[]) getAnimationScales.invoke(windowManagerObj);        for (int i = 0; i < currentScales.length; i++) {            currentScales[i] = animationScale;        }        setAnimationScales.invoke(windowManagerObj, new Object[]{currentScales});        Log.d(TAG, "Changed permissions of animations");    } catch (Exception e) {        Log.e(TAG, "Could not change animation scale to " + animationScale + " :'(");    }}}

这就是我的Espresso测试类之一(可见RecyclerVIEw列表项的DetailVIEw)

@RunWith(AndroIDJUnit4.class)public class DetailActivityTest {private IDlingResource mInitialinformationIDlingResource;@Beforepublic voID setUp() throws UiObjectNotFoundException, InterruptedException {    SetupHelper.setUp();    file tempRealmfile = new file(InstrumentationRegistry.getTargetContext().getfilesDir(), PRODUCT_REALM_DB_file_name);    if(tempRealmfile.length() <= 8192 && CustomAssertion.doesVIEwExist(R.ID.countrIEs)) {        onVIEw(withID(R.ID.countrIEs))                .check(matches(isdisplayed()));        onData(anything()).inAdapterVIEw(withID(R.ID.countrIEs)).atposition(3).perform(click());        mInitialinformationIDlingResource = new InitialinformationIDlingResource();        IDlingRegistry.getInstance().register(mInitialinformationIDlingResource);        Espresso.onVIEw(withText("OK"))                .check(matches(isdisplayed()))                .perform(click());    }}@Testpublic voID ensureDetailVIEwWorks() throws UiObjectNotFoundException {    SetupHelper.checkForDialogs();    onVIEw(withID(R.ID.show_filter_results)).perform(scrollTo());    onVIEw(withID(R.ID.show_filter_results))            .check(matches(isdisplayed())).perform(scrollTo(), click());    onVIEw(withID(R.ID.resultList)).perform(RecyclerVIEwActions.actionOnItemAtposition(1, click()));    onVIEw(withID(R.ID.main_container)).check(matches(isdisplayed()));    onVIEw(withID(R.ID.detail_item_icon)).check(matches(isdisplayed()));}

}

我在build.gradle中的构建类型

    buildTypes {    deBUG {        deBUGgable true        MinifyEnabled false        versionnameSuffix "-deBUG"        manifestPlaceholders = [HOCKEYAPP_APP_ID: ""]        testCoverageEnabled true    }    release {        MinifyEnabled false        proguardfiles getDefaultProguardfile('proguard-androID.txt'), 'proguard-rules.pro'        signingConfig signingConfigs.release        versionnameSuffix "-release"        manifestPlaceholders = [HOCKEYAPP_APP_ID: ""]    }}

解决方法:

查看设备/模拟器上的日志.在测试开始之前,app / test代码中的某些内容会崩溃. “没有发现任何测试.这通常意味着您的测试类不是您的测试运行者所期望的形式.”对你完全没有帮助=)

总结

以上是内存溢出为你收集整理的android – 从IDE运行测试但无法从命令行运行全部内容,希望文章能够帮你解决android – 从IDE运行测试但无法从命令行运行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1104873.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存