Issue
I use Android Studio 1.1.0 and created a new Android project. AS creates this new project with one ApplicationTest. When I call:
$ ./gradlew clean createDebugCoverageReport
this ApplicationTest is executed. Now I added a new test:
public class ActivityTest extends ActivityInstrumentationTestCase2<MainActivity>
But this new test isn't executed. Whats going wrong? Both test classes are in the same folder:
app\src\androidTest\java\eu.the4thfloor.testapp\
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "eu.the4thfloor.testapp"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
jacoco {
version = '0.7.3.201502191951'
}
buildTypes {
debug {
testCoverageEnabled true
}
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'
}
Solution
The problem was the wrong constructor.
AS suggested this one:
public ActivityTest(Class<MainActivity> activityClass) {
super(activityClass);
}
But with this constructor the test isn't executed. You have to use this constructor:
public ActivityTest() {
super(MainActivity.class);
}
The complete test class looks like this:
import android.test.ActivityInstrumentationTestCase2;
public class ActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
public ActivityTest() {
super(MainActivity.class);
}
public void test2() {
assertTrue(true);
}
}
Answered By - Ralph Bergmann
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.