DBAdapterで何らかのテストを行うためにAndroid Studioでテストクラスを実装しようとしています。データベースを使用するために携帯電話でテストを実行する必要があるため、私はInstrumentation Unit Testを作成しました(ユニットテストだけで実行しようとしましたが、データベースを使用する必要があります。それらはローカルでのみ実行されます)。Android Studio Junitテストパッケージorg.junitが存在しません
問題は、私はデバイスを実行しているように私の携帯電話を使用して、テストクラスを実行しようとすると、コンパイラは次のエラーをスローしていることである:私はsolutioneを探してきた
error: package org.junit does not exist
が、私見つかりませんでした。
これは私のテストクラス(単なるスケルトン)です:
import org.junit.Test;
import android.support.test.runner.AndroidJUnit4;
import static org.junit.Assert.*;
public class DbAdapterTest {
@Test
public void testCreateSeries() throws Exception {
}
}
そして、この1つはbuild.gradleスクリプトです:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.w2w.whattowatch"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
}
私はまた別の問題があります。ご覧のとおり、私はこれもインポートしました:
import android.support.test.runner.AndroidJUnit4;
しかし、実行する前に、 "ランナー"は "シンボルを解決できません"と言います。私はbuild.gradleにTestInstrumentationRunnerを追加しましたが、まだ動作していません。
あなたはユニットテストを書いている( '/ SRC/test')、またはUIテスト(' SRC/androidTest')? –
はい、計装ユニットテストなので、実行するにはsrc/androidTestにある必要があります。 http://developer.android.com/intl/es/training/testing/start/ index.html#run-instrumented-tests – gascon95
こちらをご覧ください:https://github.com/googlesamples/android-testing/tree/master/ui/espresso/BasicSampleユニットテストのために、Junitユニットを使用します。 –