Last active
August 29, 2015 13:58
-
-
Save AbeHaruhiko/10020816 to your computer and use it in GitHub Desktop.
AndroidでJUnit4を使う方法 ref: http://qiita.com/AbeHaruhiko/items/8b3b11421b431d219617
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest> | |
<!-- 下記以外は省略しています --> | |
<instrumentation | |
android:name="com.uphyca.testing.JUnit4InstrumentationTestRunner" | |
android:targetPackage="your.app.package" /> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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