- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我查看了堆栈中所有我发现有类似问题的问题,但没有一个给我一个实际有效的答案 ( https://stackoverflow.com/search?q=espresso+empty+test+suite )。
我有一个简单的项目,我想尝试 Espresso 。我的类文件如下所示:
package com.example.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FirstActivity extends Activity implements View.OnClickListener {
Button mClickMeButton;
TextView mHelloWorldTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
setupView();
}
private void setupView() {
mHelloWorldTextView = (TextView) findViewById(R.id.helloWorldTextView);
mHelloWorldTextView.setText(getTitleText());
mClickMeButton = (Button) findViewById(R.id.clickMeBtn);
mClickMeButton.setOnClickListener(this);
}
private String getTitleText() {
return "First Activity";
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
}
我的测试文件是这样的:
package com.example.myapplication.test;
import android.graphics.Bitmap;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import com.example.myapplication.BuildConfig;
import com.example.myapplication.FirstActivity;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class FirstActivityTest extends ActivityInstrumentationTestCase2<FirstActivity> {
public FirstActivityTest() {
super(FirstActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
getActivity();
}
@Test
public void testListGoesOverTheFold() {
onView(withText("First Activity")).check(matches(isDisplayed()));
}
}
和这样的 build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
apply plugin: "sonar-runner"
apply plugin: 'spoon'
android {
compileSdkVersion 21
buildToolsVersion '22.0.1'
packagingOptions {
exclude 'LICENSE.txt'
}
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
testApplicationId "com.example.myapplication.test"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
testCompile 'org.easytesting:fest:1.0.16'
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'com.squareup:fest-android:1.0.8'
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.9'
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
exclude group: 'javax.inject'
}
}
spoon {
debug = true
//devices = ['333236E9AE5800EC']
if (project.hasProperty('spoonClassName')){
className = project.spoonClassName
}
}
}
def coverageSourceDirs = [
'../app/src/main/java', 'src/gen'
]
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}
classDirectories = fileTree(
dir: './build/intermediates/classes/debug',
excludes: ['**/R.class',
'**/R$*.class'
])
sourceDirectories = files(coverageSourceDirs)
executionData = files('build/jacoco/testDebug.exec')
}
}
每次我尝试运行它时,我都会得到:
Testing started at 16:57 ...
Target device: genymotion-google_nexus_5___5_0_0___api_21___1080x1920-192.168.56.101:5555
Uploading file
local path: /Users/pernillauhlin/development/pingdom/android-robolectric-test/app/build/outputs/apk/app-debug.apk
remote path: /data/local/tmp/com.example.myapplication
No apk changes detected. Skipping file upload, force stopping package instead.
DEVICE SHELL COMMAND: am force-stop com.example.myapplication
Uploading file
local path: /Users/pernillauhlin/development/pingdom/android-robolectric-test/app/build/outputs/apk/app-debug-androidTest-unaligned.apk
remote path: /data/local/tmp/com.example.myapplication.test
No apk changes detected. Skipping file upload, force stopping package instead.
DEVICE SHELL COMMAND: am force-stop com.example.myapplication.test
Running tests
Test running startedTest running failed: Unable to find instrumentation info for: ComponentInfo{com.example.myapplication.test/android.test.InstrumentationTestRunner}
Empty test suite.
我的结构是:
此外,从命令运行勺子给我同样的结果。所以,我的问题是:
编辑:
我的运行配置如下所示:
看起来 android.support.test.runner.AndroidJUnitRunner 不存在。
构建变体:
最佳答案
我通过在测试配置中设置错误 android.test.InstrumentationTestRunner
成功重现了您的情况。
我建议检查您是否有正确的-android.support.test.runner.AndroidJUnitRunner
-(或没有)在运行菜单中指定|编辑配置。
此外,您的问题的标题有些令人困惑,因为从构建 gradle 依赖关系来看,我的理解是您实际上是在使用 Espresso 2.1。如果这是真的,请注意:
TestCases like ActivityInstrumentationTestCase2 or ServiceTestCase are deprecated in favor of ActivityTestRule or ServiceTestRule.
也可以看出here或 here ,注释将按以下方式使用:(将调整您弃用的测试类只是因为我很好)
//annotate JUnit4 test classes with
@RunWith(AndroidJunit4.class)
@LargeTest
public class FirstActivityTest {
//use the following annotation and declare an ActivityTestRule for your activity under test
@Rule
public ActivityTestRule<FirstActivity> mActivityRule = new ActivityTestRule(FirstActivity.class);
//use @Before to setup your test fixture
@Before
public void setUp() { ... }
//annotate all test methods with
@Test
public void testHelloWorld() { ... }
//release resources by using
@After
public void tearDown() { ... }
}
更多关于 Rules
了解更多关于 test size annotations 的其他好地方
关于android - Espresso 2.1 找不到我的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30127135/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!