我通知我的UI测试停止了工作:
每当我尝试在设备上运行测试时,我收到以下消息:
未找到任何测试
附加控制台输出说:
Running tests
Test running startedTest running failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'
Empty test suite.
当我尝试在模拟器上运行测试时,我收到以下消息:
Test running started
java.lang.IncompatibleClassChangeError:
view.activity.SignUpActivity
SignUpActivityTest.<init>(SignUpActivityTest.java:25)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:228)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)
Finish
以下是测试类的示例:
import android.app.Activity;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import xxxx.view.activity.SignUpActivity;
@RunWith(AndroidJUnit4.class)
public class SignUpActivityTest extends ActivityInstrumentationTestCase2<SignUpActivity> {
private Activity mActivity;
public SignUpActivityTest() {
super(SignUpActivity.class);
}
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
// Insert scenario methods here
@Test
public void processTest() throws InterruptedException {
TestHelper th = new TestHelper();
th.insertTextIntoInput(R.id.input_sign_in_username, "test");
}
}
build.gradle 文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "cz.xxx.xxx"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.commonsware.com.s3.amazonaws.com" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.orhanobut:logger:1.11'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:design:23.0.0'
// UI TESTING DEPENDENCIES
androidTestCompile 'com.android.support:support-annotations:23.0.0'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
//androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
// ORM DATABASE DEPENDENCIES
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
// STETHO CORE
compile 'com.facebook.stetho:stetho:1.1.1'
compile 'com.facebook.stetho:stetho-urlconnection:1.1.1'
compile 'com.facebook.stetho:stetho-okhttp:1.1.1'
// GOOGLE ANALYTICS
compile 'com.google.android.gms:play-services-analytics:7.8.0'
// JODA TIME FOR ANDROID
compile 'net.danlew:android.joda:2.8.2'
// SECURE SHARED PREFERENCES
compile 'com.scottyab:secure-preferences-lib:0.1.3'
// MATERIAL DIALOG
compile 'com.avast:android-styled-dialogs:2.2.0'
// SQL CIPHER
compile 'com.commonsware.cwac:sqlcipher-for-android:3.3.1'
// HTML PARSER
compile 'org.jsoup:jsoup:1.8.3'
// MULTIDEX SUPPORT
compile 'com.android.support:multidex:1.0.0'
}
我几乎尝试了一切来解决它,但没有运气。也许有些人给我一个正确的答案。
非常感谢您的任何建议。
修改 我试图在&#34;特定仪器运行器&#34;中显示运行/调试配置。输入什么都没有。
所以我插入了以下内容(参见下图),但部分字符串AndroidJUnitRunner为红色。
答案 0 :(得分:1)
测试名称应以
开头test
尝试将测试重命名为以下内容并重新运行
testprocessTest()