0
이전에 JUnit을 사용한 적은 한번도 없었으므로 검색 한 결과 roboelectric이라는 좋은 도구가 있습니다.로봇 전기 테스트
웹 사이트에 표시된 것처럼 간단한 테스트를 실행하려고하지만 assertThat() 및 shadowOf()가 인식되지 않습니다.
다음은 테스트
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class MainActivityTest {
@Test
public void clickingLogin_shouldStartLoginActivity() {
MainActivity activity = Robolectric.setupActivity(MainActivity.class);
activity.findViewById(R.id.login).performClick();
Intent expectedIntent = new Intent(activity, LoginActivity.class);
//This line doesn't work.
assertThat(shadowOf(activity).getNextStartedActivity()).
isEqualTo(expectedIntent);
}
}
그리고이 어떻게 Gradle을에 Roboelectric을 설정합니다.
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "testing.theo.robotutorial"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
testCompile "org.robolectric:robolectric:3.0"
}
아이디어가 있으십니까?
감사합니다.