Skip to content

Instantly share code, notes, and snippets.

@AbeHaruhiko
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbeHaruhiko/10020816 to your computer and use it in GitHub Desktop.
Save AbeHaruhiko/10020816 to your computer and use it in GitHub Desktop.
AndroidでJUnit4を使う方法 ref: http://qiita.com/AbeHaruhiko/items/8b3b11421b431d219617
<manifest>
<!-- 下記以外は省略しています -->
<instrumentation
android:name="com.uphyca.testing.JUnit4InstrumentationTestRunner"
android:targetPackage="your.app.package" />
</manifest>
import com.uphyca.testing.AndroidTestCase;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
// com.uphyca.testing.AndroidTestCase を extends
public class AndroidUtilTest extends AndroidTestCase {
@Test(expected = IllegalArgumentException.class)
public void checkの引数がnullの時IllegalArgumentExceptionが送出される() {
AndroidUtil.check(null);
}
}
android {
defaultConfig {
testInstrumentationRunner "com.uphyca.testing.JUnit4InstrumentationTestRunner"
}
dependencies {
// 行末のバージョン指定(4.+ 等)は適宜変更
androidTestCompile ("junit:junit:4.+")
androidTestCompile ("com.uphyca:android-junit4:+")
}
// LICENS.txtがどうのこうのというエラーが出たら、他のjarと競合しているので下記の記述を追加。
// パスはAndroidStudioの「Project」ペインでjarの中身を見て適宜変更。
// (AndroidStudioのバグらしい)
packagingOptions {
// for AndroidStudio's bug. duplication error of file below.
pickFirst 'META-INF/LICENSE.txt'
pickFirst 'LICENSE.txt'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment