Skip to content

Commit

Permalink
espressoテストコードサンプル作成
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitsuru Shinmura committed Dec 30, 2013
1 parent 5dff08c commit e7fd22e
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
mokumoku
========
Android勉強会用プロジェクト

practice aplication
mkmk_otohime
スイッチonで音が鳴るandroid.mediaを使用するサンプル

mkmk_otohime_espresso_test
espressoでのテストコードを試したサンプル
実行時にeclipse上で「実行の構成」 テストタブのInstrumentation runner を
com.google.android.apps.commons.testing.testrunner.GoogleInstrumentation.TestRunnerに変更する。
それ以外はJUnitと同様。
13 changes: 13 additions & 0 deletions .gitignore → mkmk_otohime/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ local.properties
# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

# Robot Framework Test Server
test_servers/

2 changes: 1 addition & 1 deletion mkmk_otohime/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
tools:context=".MainActivity" >

<TextView
android:id="@+id/textView1"
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dont search mantaroh?" />
Expand Down
33 changes: 33 additions & 0 deletions mkmk_otohime_espresso_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

# Robot Framework Test Server
test_servers/

23 changes: 23 additions & 0 deletions mkmk_otohime_espresso_test/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mkmk_otohime.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="14" />

<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.mkmk_otohime" />

<instrumentation
android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
android:targetPackage="com.example.mkmk_otohime" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>

</manifest>
Binary file not shown.
20 changes: 20 additions & 0 deletions mkmk_otohime_espresso_test/proguard-project.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
14 changes: 14 additions & 0 deletions mkmk_otohime_espresso_test/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions mkmk_otohime_espresso_test/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Mkmk_otohime_espresso_testTest</string>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.mkmk_otohime.test;

import com.example.mkmk_otohime.MainActivity;
import com.example.mkmk_otohime.R;
import android.test.ActivityInstrumentationTestCase2;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.pressBack;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.closeSoftKeyboard;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {

public MainActivityTest(Class<MainActivity> activityClass) {
super(activityClass);
}

public MainActivityTest() {
super(MainActivity.class);
}

@Override
public void setUp() throws Exception {
super.setUp();
// Espresso will not launch our activity for us, we must launch it via
// getActivity().
getActivity();
}
public void testdisplayName() {
// TextViewにメッセージが表示されるかチェック
onView(withId(R.id.textView1)).check(matches(withText("OTOHIME")));
}

}

0 comments on commit e7fd22e

Please sign in to comment.