gpt4 book ai didi

java - AndroidJUnitRunner 不运行包中的测试

转载 作者:行者123 更新时间:2023-12-01 11:24:50 25 4
gpt4 key购买 nike

只要指定类,我就可以运行仪器测试。

adb shell am instrument -w -e class com.application.instrumentation.BaseActivityTest com.application.debug.test/android.support.test.runner.AndroidJUnitRunner

com.application.instrumentation.BaseActivityTest:.

Time: 2.204

OK (1 test)

我的所有仪器测试都位于com.application.instrumentation包中。当我尝试运行此包中的所有测试时,检测无法找到任何测试。

adb shell am instrument -w -r -e package com.application.instrumentation com.application.debug.test/android.support.test.runner.AndroidJUnitRunner
INSTRUMENTATION_RESULT: stream=

Time: 0

OK (0 tests)


INSTRUMENTATION_CODE: -1

AndroidStudio 相同 - 我能够在特定类中运行测试,而不是在整个包中运行测试。

BaseActivityTest.java

@RunWith(AndroidJUnit4.class)
@LargeTest
public class BaseActivityTest
extends ActivityInstrumentationTestCase2<BaseActivity> {

private BaseActivity mActivity;

public BaseActivityTest() {
super(BaseActivity.class);
}

@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}

@Test
public void checkPreconditions() {
assertThat(mActivity, notNullValue());
// Check that Instrumentation was correctly injected in setUp()
assertThat(getInstrumentation(), notNullValue());
}

@After
public void tearDown() throws Exception {
super.tearDown();
}

}

AndroidStudio版本为1.2.2

测试依赖关系:

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}

可用仪器:

adb shell pm list instrumentation
instrumentation:com.application.debug.test/android.support.test.runner.AndroidJUnitRunner (target=com.application.debug)

最佳答案

我相信这是因为 JUnit4 风格的测试类不应该扩展 ActivityInstrumentationTestCase2<BaseActivity> 。只需省略该部分并且不扩展任何类,请参阅例如this example .

关于java - AndroidJUnitRunner 不运行包中的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30910254/

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