lit*_*019 10 android android-testing android-espresso
I need to do some auto testing jobs to an Android application without its source code. I found both robotium and espresso can do this job, I decided to use espresso because its Google support.
I would like to sign both the target apk and espresso test apk with the same signature, the target apk is the same as this sample.

When I start to coding the espresso test apk, I did the following jobs.
The build.gradle in Module:app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "tk.deedog.i01test"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}
Run Code Online (Sandbox Code Playgroud)
The source code of my I01Test.java:
package tk.deedog.i01test;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
public class I01Test extends ActivityInstrumentationTestCase2 {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "tk.tubabe.instrustmen101.Instruments101";
private static Class<?> launcherActivityClass;
Activity i101Acitvity;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public I01Test() {
super(launcherActivityClass);
}
@Override
protected void setUp() throws Exception {
super.setUp();
i101Acitvity = getActivity();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
public void testButtonClick() {
onView(withText("Send")).perform(click());
}
}
Run Code Online (Sandbox Code Playgroud)
When I tried to run this program, Android studio told me that Error:(6, 44) error: package android.support.test.espresso does not exist.
我遇到了同样的问题,以下一行代码破坏了我的测试版本:
main { java.srcDirs = ['src/main/java', 'src/AndroidTests', 'src/AndroidTest/java'] }
Run Code Online (Sandbox Code Playgroud)
从srcDirs删除测试代码:
sourceSets {
....
main { java.srcDirs = ['src/main/java'] }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9710 次 |
| 最近记录: |