SlideShare a Scribd company logo
1 of 29
Download to read offline
和田 佳大(@e10dokup)
Code for kosen 勉強会 #3
自己紹介
和田 佳大(@e10dokup)
・明石高専 E49(卒業生)
・Code for KOSEN:Branch Akashi のクソメガネ
・興味対象
↑
最近始めた
自己紹介
自己紹介
残念なお知らせ
この発表には以下の点が含まれます
・Android 未経験者ガン無視
・身内要素
・noob
・ライオン
「知らねぇよ!!!」って方もこの機会に Android
開発に興味を持っていただければ(?)
今回の話題
今回の話題
と
テストのお話
今回の話題
と
テストのお話
今回の話題
と
テストのお話
今回の話題
テストを書いてないと…
・変更する際の「壊す恐怖」
・祈りながらの開発
今回の話題
テストを書いてないと…
・変更する際の「壊す恐怖」
・祈りながらの開発
でも Android のテストは…
・記事が少ない
・Activity とか難解なテストが多い
今回の話題
_人人人人人人人人人人_
> Androidのテスト大変 <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄
今回の話題
_人人人人人人人人人人_
> じゃあ勉強しよう <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄
テスト用ライブラリ ?
ググるとなんか出てくる
・JUnit4
・Espresso
・Roborectric
・Robotium
とか
テスト用ライブラリ ?
ググるとなんか出てくる
・JUnit4
・Espresso
・Roborectric
・Robotium
とか
2014/12 Android SDK でサポート
2014/12 Support Library に追加
テスト用ライブラリ ?
(標準で使えそうなので…)
・JUnit4
・Espresso
2014/12 Android SDK でサポート
2014/12 Support Library に追加
を使っていきます
導入
build.gradle
android {
・・・
defaultConfig {
・・・
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'LICENSE.txt'
}
・・・
}
LICENSE.txt が重複するので追記
導入
build.gradle
dependencies {
・・・
compile 'com.android.support:support-annotations:22.1.1'
androidTestCompile
'com.android.support.test:testing-support-lib:0.1'
androidTestCompile
'com.android.support.test.espresso:espresso-core:2.0'
}
ユニットテスト
・app/src/androidTest/java/ApplicationID
内にテストクラスを入れる
・AndroidTestCase を継承
・@RunWith(AndroidJUnit4.class) をつける
・テストメソッドには @Test をつける
ユニットテスト
サンプル
@RunWith(AndroidJUnit4.class)
public class TestSample extends AndroidTestCase{
@Test
public void sample() throws Exception{
asserEquals(334, 330+4); //なんでや!
}
}
UI テスト
・app/src/androidTest/java/ApplicationID
内にテストクラスを入れる
・ActivityInstrumentationTestCase2 を継承
・@RunWith(AndroidJUnit4.class) をつける
・テストメソッドには @Test をつける
・setUp(),tearDown() をつける
UI テスト
・ViewMatcher で View を指定して
・ViewAction で View を操作して
・ViewAssertion で View の状態を確認する
Espresso による UI テスト?
UI テスト
サンプル
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MyJunit4ActivityInstrumentationTest
extends ActivityInstrumentationTestCase2<MyActivity> {
private MyActivity mActivity;
public MyJunit4ActivityInstrumentationTest() {
super(MyActivity.class);
}
UI テスト
サンプル(続)
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry
.getInstrumentation());
mActivity = getActivity();
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
UI テスト
サンプル(続)
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry
.getInstrumentation());
mActivity = getActivity();
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
オブジェクトのリークを回避
UI テスト
サンプル(続)
@Test
public void testHoge(){
Espresso.onView(ViewMatchers.withId(R.id.text_hoge))
.check(ViewAssertions
.matches(ViewMatchers.withText("Test")));
}
テストの実行
Android Studio の場合
・Run > Edit Configuration
・+ ボタンから Android Tests を追加
・module 等を指定して OK で完了
・アプリの実行と同様にテストを走らせる
おわりに
・僕はテストがかけません(ちょっと勉強しただけ)
・Google 様が UI テストは Espresso 使えって
言ってた
・工数が増えるけど精神の安寧を保つために
テスト書けるようになろうな
あ り が と う ご ざ い ま し た

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Code for KOSEN meetup #3