Last active
August 29, 2015 14:26
-
-
Save t-kashima/9b7e0cfe99ec0ae33583 to your computer and use it in GitHub Desktop.
Espressoを使ったテスト
This file contains hidden or 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
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 22 | |
buildToolsVersion "22.0.1" | |
defaultConfig { | |
applicationId "com.unuuu.myapp" | |
minSdkVersion 14 | |
targetSdkVersion 22 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
packagingOptions { | |
exclude 'LICENSE.txt' | |
} | |
} | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
compile 'com.android.support:appcompat-v7:22.2.0' | |
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' | |
androidTestCompile 'com.android.support.test:testing-support-lib:0.1' | |
} |
This file contains hidden or 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
package com.unuuu.myapp; | |
import android.support.test.InstrumentationRegistry; | |
import android.support.test.espresso.Espresso; | |
import android.support.test.espresso.assertion.ViewAssertions; | |
import android.support.test.espresso.matcher.ViewMatchers; | |
import android.support.test.runner.AndroidJUnit4; | |
import android.test.ActivityInstrumentationTestCase2; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
@RunWith(AndroidJUnit4.class) | |
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> { | |
private MainActivity mMainActivity; | |
public MainActivityTest() { | |
super(MainActivity.class); | |
} | |
@Before | |
public void setUp() throws Exception { | |
super.setUp(); | |
injectInstrumentation(InstrumentationRegistry.getInstrumentation()); | |
this.mMainActivity = getActivity(); | |
} | |
@Test | |
public void テストのテスト() { | |
Espresso.onView(ViewMatchers.withId(R.id.fragment_main_frame_001)).check(ViewAssertions.matches(ViewMatchers.withText("Hello world!"))); | |
} | |
@After | |
public void tearDown() throws Exception { | |
super.tearDown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment