ES $ P $ 2.1 PSSO没有找到我的测试 [英] Espresso 2.1 doesn't find my tests
问题描述
我已经通过堆栈我发现类似的问题,所有的问题看,但没有给我一个答案,其实工作(<一个href=\"http://stackoverflow.com/search?q=es$p$psso+empty+test+suite\">http://stackoverflow.com/search?q=es$p$psso+empty+test+suite).
I have looked through all the questions on stack I found with similar problem, but none has given me an answer that actually work (http://stackoverflow.com/search?q=espresso+empty+test+suite).
我有一个简单的项目,我想在PSSO尝试ES $ P $。我的类文件看起来是这样的:
I have a simple project I want to try espresso on. My class file looks like this:
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);
}
}
我的测试文件是这样的:
My test file look like this:
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是这样的:
and the build.gradle like this:
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')
}
}
每当我尝试运行它,我得到:
Every time I try to run it, I get:
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.
我的结构是:
另外,从命令运行勺子给我同样的结果。所以,我的问题是:
Also, running spoon from command give me the same result. So, my question is:
- 我缺少什么?
- 用于测试的注释;我已经看到了很多的变化,上面的类,测试前等。什么是正确的方法是什么?或者,你可以在课前指定@LargeTest和实际测试方法之前@SmallTest?
编辑:
我的运行配置是这样的:
My run configuration looks like this:
它看起来像android.support.test.runner.AndroidJUnitRunner不存在。
It looks like android.support.test.runner.AndroidJUnitRunner doesn't exist.
构建变种:
推荐答案
我设法通过设置在错误 android.test.InstrumentationTestRunner $ C $重现您的情况C>在测试配置。
I managed to reproduce your situation by setting the wrong android.test.InstrumentationTestRunner
in the test configuration.
我会建议检查如果你有正确的 - android.support.test.runner.AndroidJUnitRunner
- (或无)在运行菜单中指定|编辑配置即可。
I would suggest checking if you have the correct one -android.support.test.runner.AndroidJUnitRunner
- (or none) specified in the Run menu | Edit Configurations.
另外,你的问题的标题是有点令人困惑,因为从构建依赖的gradle,我的理解是,你真的要为长者$ P $ 2.1 PSSO。如果这是真的,还要注意:
Also, your question's title is somewhat confusing, since from the build gradle dependencies, my understanding is that you're actually going for Espresso 2.1. If that is true, also note that:
像ActivityInstrumentationTestCase2或ServiceTestCase的TestCase赞成ActivityTestRule或ServiceTestRule的pcated德$ P $。
TestCases like ActivityInstrumentationTestCase2 or ServiceTestCase are deprecated in favor of ActivityTestRule or ServiceTestRule.
作为它也可以看出此处或<一个href=\"https://docs.google.com/$p$psentation/d/1EtFKPluGiuxZcr4W_cAziEY_--wbY_1otw44XEBv7JA/edit#slide=id.g98a986571_0_137\"相对=nofollow>此处的注释以下列方式使用:(将调整你去precated测试类只是因为我很漂亮)
As it can also be seen here or here, the annotations are to be used in the following way: (will adjust your deprecated test class just because I'm nice)
//annotate JUnit4 test classes with
@RunWith(AndroiJunit4.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() { ... }
}
更多关于规则
其它伟大的地方,了解更多有关测试尺寸标注
Other great place to find out more about test size annotations
这篇关于ES $ P $ 2.1 PSSO没有找到我的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!