Đây là tập tin gradle tôi:Android Studio với Robolectric: kiểm tra lớp học của tôi không được tìm thấy
apply plugin: 'android'
apply plugin: 'android-test'
android {
// Check on it to know witch Android API level is necessary:
// http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
androidTest {
setRoot('src/test')
}
}
// Patch: http://stackoverflow.com/questions/20673888/duplicate-files-copied-android-studio-0-4-0
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
androidTest {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
dependencies {
// Android SDK Extra librairies
compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:appcompat-v7:19.0.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
// Android testing
// http://robolectric.org/
androidTestCompile 'junit:junit:4.+'
androidTestCompile 'org.robolectric:robolectric:2.+'
androidTestCompile 'com.squareup:fest-android:1.0.+'
// had to deploy to sonatype to get AAR to work
//compile 'com.novoda:actionbarsherlock:4.3.2-SNAPSHOT'
}
này gốc của tôi gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
//classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
//classpath 'com.novoda.gradle:robolectric-plugin:0.0.1-SNAPSHOT'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+'
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
}
Tôi chỉ viết một cách dễ dàng lớp để kiểm tra để xác thực kiểm tra cơ sở hạ tầng của tôi, nhưng tôi có lỗi này:
Class not found: "com.example.myapp.activity.BaseActivityTest"
kiểm tra lớp của tôi là:
package com.example.myapp.activity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.*;
@RunWith(RobolectricTestRunner.class)
public class BaseActivityTest {
@Test
public void testTrueIsTrue() throws Exception {
assertEquals(true, true);
}
}
achitecture thư mục của tôi là:
myapp
src
chính
012.- java
- com.example.myapp ...
- java
kiểm tra
- java
- com.example.myapp ...
- java
Tôi không hiểu tại sao lỗi này xuất hiện.
Cảm ơn các bạn!
Hey Anthony, Tôi đã thiết lập công việc cho Android Studio 0.4.6 nhưng biết rằng phiên bản Android studio sau này đã gây ra sự cố - tôi đã hỏi [câu hỏi này] (http://stackoverflow.com/q/23116409/1348379) cho một phản ứng của im lặng điếc! Bạn đang chạy phiên bản AS nào? – OceanLife
Hey OceanLife! Đó là phiên bản cuối cùng 0.5.5. Cảm ơn! – anthony