内容へ移動
MSS Wiki 開発者ブログ (メモ?)
ユーザ用ツール
ログイン
サイト用ツール
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
最近の変更
メディアマネージャー
サイトマップ
トレース:
junit4
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
■注意点\\ ・ビルドツール(build.gradle)のバージョンが1.0.0以上の必要がある。\\ ・ビルドタイプが「debug」でしかテストされない。「release」でも行いたい場合は下記を追加する。\\ android { // ... testBuildType "release" } ■ビルドファイルの設定\\ ・build.gradle(app)\\ android {\\ defaultConfig {\\ // ...\\ \\ testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"\\ }\\ }\\ dependencies {\\ // ...\\ \\ // runner及びrulesはtestingライブラリより分割された (旧:testing-support-lib)\\ androidTestCompile 'com.android.support:support-annotations:23.0.0'\\ androidTestCompile 'com.android.support.test:runner:0.3'\\ androidTestCompile 'com.android.support.test:rules:0.3'\\ }\\ ■テストコードの作成\\ パッケージ名(androidTest)ディレクトリにテストコードを作成します。\\ デフォルトでApplicationTestというクラスが生成されている場所です。\\ - JUnit 4 で実装されたテストクラスには @RunWith(AndroidJUnit4.class) をつける\\ - テスト対象メソッドには @Test をつける\\ - setUp() を Override し、public に変更し @Before をつける\\ - tearDown() を Override し、public に変更し @After をつける\\ - 必要に応じて AndroidTestCase.setContext(InstrumentationRegistry.getContext()) や \\InstrumentationTestCase.injectInstrumentation(InstrumentationRegistry.getInstrumentation()) を setUp() で行う\\ - メソッド名の命名規則として先頭にtestをつける (例: testHoge())\\ ・ちょっと裏ワザ\\ テストしたいクラス名を選択した状態でAlt + Enterで一括でテスト関数を生成出来る。\\ ---------------------------------\\ @RunWith(AndroidJUnit4.class)\\ public class MetricsTest extends AndroidTestCase {\\ \\ @Before\\ public void setUp() throws Exception {\\ super.setUp();\\ // instrumentation のパッケージContext\\ setContext(InstrumentationRegistry.getContext());\\ }\\ \\ @After\\ public void tearDown() throws Exception {\\ super.tearDown();\\ }\\ }\\ ■メソッドについて\\ // 予想, 実際\\ assertEquals(expected, actual);\\ ■ run > setting (実行 > デバッグ設定)\\ +を押下\\ Android Tests\\ 名前を入力\\ Moduleでappを選択\\ USBデバイスでテストを実行する場合は、USB Deviceにチェックを入れる\\ 適用 > OK\\ ■参考URL\\ Android JUnit 4 形式のテストにする\\ http://y-anz-m.blogspot.jp/2015/08/androidjunit-4.html\\ Build High-Quality Apps\\ https://google.github.io/android-testing-support-library/\\ Building Instrumented Unit Tests\\ https://developer.android.com/intl/ja/training/testing/unit-testing/instrumented-unit-tests.html\\ http://mixi-inc.github.io/AndroidTraining/fundamentals/2.11.testing.html\\
junit4.1444653079.txt.gz
· 最終更新: 2015/10/12 21:31 by
sou
ページ用ツール
文書の表示
以前のリビジョン
バックリンク
文書の先頭へ