I am trying to write an instrumentation test for my MainActivity. I followed the answers given here. Still Android Studio cannot find any tests. I have the class ApplicationTest.java in the androidTest folder. Here's the contents of the class:
package com.example.monicamarcus.mymusicplayer
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import com.example.monicamarcus.mymusicplayer.MainActivity;
public class ApplicationTest extends ActivityInstrumentationTestCase2<MainActivity> {
public ApplicationTest() {
super(MainActivity.class);
}
public void testNextTrackButton() throws Exception {
Activity activity = getActivity();
Button nextButton = (Button) activity.findViewById(R.id.nextTrackBt);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
nextButton.performClick();
assertTrue(currentPosition < songList.size());
}});
activity.finish();
}
}
What is wrong with this test class? Or with the tests? I don't get any error, it just does not find any test to run. After I run the ApplicationTest the output ends with the following lines:
Running tests
Test running startedFinish
Empty test suite.
Here's the build.gradle file for the app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.monicamarcus.mymusicplayer"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
testApplicationId "app.src.androidTest.java.com.example.monicamarcus.mymusicplayer"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
useLibrary 'org.apache.http.legacy'
}
android {
sourceSets {
androidTest {
java.srcDirs = ['androidTest/java']
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
androidTestCompile 'junit:junit:4.12'
}
Here's the output of the test run:
Testing started at 1:56 PM ...
Target device: gt_i8190n-4790068ee9a750c6
Installing APK: /Users/monicamarcus/AndroidStudioProjects/MyMusicPlayer/app/build/outputs/apk/app-debug.apk
Uploading file to: /data/local/tmp/com.example.monicamarcus.mymusicplayer
Installing com.example.monicamarcus.mymusicplayer
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.monicamarcus.mymusicplayer"
pkg: /data/local/tmp/com.example.monicamarcus.mymusicplayer
Success
Installing APK: /Users/monicamarcus/AndroidStudioProjects/MyMusicPlayer/app/build/outputs/apk/app-debug-androidTest-unaligned.apk
Uploading file to: /data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
Installing app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer"
pkg: /data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
Success
Running tests
Test running startedFinish
Empty test suite.
After I made some changes (I can publish them if anybody is interested) the result of running the instrumentation test class read as follows: "Running tests. Test running started. Test running failed: No test results. Empty test suite." Nobody has experience with these kind of tests?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…