나는 Junit 3을 기반으로 한 기존 AndroidTestCase 유닛 테스트가 포함 된 Android Studio 프로젝트를 가지고 있습니다. AndroidTestCase 테스트를 대체하지 않고 보완하기 위해 robolectric 테스트를 소개합니다. 동일한 프로젝트에서 Junit 3 기반 AndroidTestCase 테스트와 Junit 4 기반 Robolectric 테스트를 모두 사용할 수 있습니까? 대나무 CI 시스템에서 둘 다 실행할 수 있습니까? 이를 지원하도록 프로젝트를 어떻게 구성합니까?동일한 Android 프로젝트에서 Junit 3과 Junit 4를 모두 사용할 수 있습니까?
2
A
답변
1
같은 프로젝트에서 Robolectric 테스트를 별도의 모듈에 넣는 것이 좋습니다.
새 모듈을 만들려면 파일 -> 새 모듈 -> Java 라이브러리로 이동하십시오. 해당 모듈을 만들 때, 그 build.gradle
파일로 이동 한 다음과 같은 라인의 내용을 대체 :이 Robolectric 시험 선 (善)과 모듈을 청구
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
repositories {
mavenLocal()
maven { url "$System.env.ANDROID_HOME/extras/android/m2repository" } // Fix 'com.android.support:*' package not found issue
mavenCentral()
}
evaluationDependsOn(":app")
apply plugin: 'java'
dependencies {
def androidModule = project(':app')
testCompile project(path: ':app', configuration: 'debugCompile')
def debugVariant = androidModule.android.applicationVariants.find({it.name == 'debug'})
testCompile debugVariant.javaCompile.classpath
testCompile debugVariant.javaCompile.outputs.files
testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())
testCompile 'org.hamcrest:hamcrest-integration:1.1'
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
testCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
testCompile "org.mockito:mockito-core:1.9.5"
testCompile 'org.assertj:assertj-core:1.6.1'
}
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Should.class"
include "**/*Test.class"
include "**/*Tests.class"
}
과 좋은 출발점 역할을한다.
:app
은 응용 프로그램 모듈의 이름으로 대체해야합니다. Robolectric 시험
, 당신은 또한 다음과 같을 수도 Robolectric 러너를 필요 :
public class ApplicationTestRunner extends RobolectricTestRunner {
//Maximun SDK Robolectric will compile (issues with SDK > 18)
private static final int MAX_SDK_SUPPORTED_BY_ROBOLECTRIC = 18;
private static final String ANDROID_MANIFEST_PATH = "../app/src/main/AndroidManifest.xml";
private static final String ANDROID_MANIFEST_RES_PATH = "../app/src/main/res";
/**
* Call this constructor to specify the location of resources and AndroidManifest.xml.
*
* @throws org.junit.runners.model.InitializationError
*/
public ApplicationTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
}
@Override protected AndroidManifest getAppManifest(Config config) {
return new AndroidManifest(Fs.fileFromPath(ANDROID_MANIFEST_PATH),
Fs.fileFromPath(ANDROID_MANIFEST_RES_PATH)) {
@Override
public int getTargetSdkVersion() {
return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC;
}
};
}
}
그럼 그냥 예를 들어,이 주자와 테스트 클래스에 주석 : Robolectric에서
@RunWith(ApplicationTestRunner.class)
public class PriorityExecutorSchedulerTest {
....
}
테스트 모듈은 gradlew test
으로 실행할 수 있습니다.
Bamboo와 관련하여 AFAIK에는 사용자 지정 스크립트를 실행할 가능성이 있으므로 그냥 gradlew test
을 입력하고 어떻게 진행되는지 확인하십시오.
관련 문제
- 1. 동일한 프로젝트에서 Android JUnit 클래스와 일반 JUnit 클래스를 혼합하는 방법
- 2. 선인장과 junit 4를 동일하게 사용하십시오
- 3. JUnit 4를 사용한 intel의 분해.
- 4. 프로젝트에서 오류가있는 Android JUnit 테스트를 실행할 수 있습니까?
- 5. Android 프로젝트에서 JUnit 테스트를 수행 할 위치
- 6. Java/Junit 4를 사용하면 컴파일 오류가 발생합니다.
- 7. JUnit 테스트에서 java.lang.instrument.Instrumentation을 사용할 수 있습니까?
- 8. JUnit 테스트에서 JMS를 사용할 수 있습니까?
- 9. Envers 4를 Hibernate 3과 함께 사용할 수 있습니까?
- 10. Android JUnit 환경 설정
- 11. Android Junit 테스팅 동결
- 12. Eclipse 프로젝트에서 JUnit 4 실행하기
- 13. Android 액티비티 Junit 테스트
- 14. 파일로 Android JUnit 테스트
- 15. 동일한 프로젝트에서 LESS와 SCSS를 모두 사용할 수 있습니까? 아니면 변환해야합니까?
- 16. Android : jUnit Android 라이브러리 테스트
- 17. Android jUnit 테스트 오류
- 18. Android JUnit testing ClassNotFoundException
- 19. android : junit 보고서 생성
- 20. android JUnit Tests not
- 21. Android Eclipse JUnit 프로젝트의 개별 클래스에서 vanilla JUnit 테스트를 실행합니다.
- 22. java.lang.RuntimeException : 스텁! 안드로이드 프로젝트에서 Junit 실행하기
- 23. 콘솔에서 모든 junit 테스트를 프로젝트에서 실행할 수 있습니까?
- 24. 뮬의 org.mule.tck.FunctionalTestCase를 사용할 때 JUnit 주석을 사용할 수 있습니까?
- 25. junit 4를 Eclipse의 기본 러너로 설정하는 방법, 안드로이드 테스트 프로젝트
- 26. Junit 메소드의 Java-Junit/오해
- 27. junit 4에는 MbUnit의 AssemblySetUp 속성과 동일한 기능이 있습니까?
- 28. ant-junit 1.5.3 jar을 사용할 수 없습니다.
- 29. Android JUnit Test suite를 JAR 파일로 압축 할 수 있습니까?
- 30. Junit 테스트에서 Mocking android method
나는 클래스를 필터링하거나 다른 폴더에 넣을 수 있으며, android 테스트를 빌드하고 실행할 때 robolectric 테스트 클래스를 제거 할 수 있습니다. robolectric 테스트를 실행할 때 안드로이드 테스트를 필터링 할 수 있습니다. 그러나 동시에이 프로젝트의 설치가 구현, 이해 및 지원하기가 어려울 것으로 기대합니다. 나는 다른 모듈에서 안드로이드 나 로보트 테스트를 옮길 것이지만 같은 프로젝트에서 안드로이드와 로보 테스트를하는 데 많은 경험이 없다. –