SlideShare a Scribd company logo
JUnit for Android
@nory_kaname
● MUST do TDD
● Android has Test Framework
● We'll use "Android Testing Support Library"
○ test helper libary
まとめ
Note : "MUST": RFC2119
Android Test Policy
Debugging and testing in Android Studio (Ep 4, Android Studio)
https://youtu.be/2I6fuD20qlY
Test driven development
Test First
Test MUST run on Master branch!!
Test fundamental in Android
Android
Test frameworks
2 type of JUnit
● Normal JUnit (3.0 , 4.0)
○ running on JVM
○ Java class , module test
● Android JUnit (3.0 , 4.0)
○ running on Adroid Device(Emulator)
○ UI Testing
Learn JUnit
● Recommend Books
UI Testing
Tools
● Android Studio
● Espresso(android-test-kit, for Google)
Layout file
Layout file to configure the screen.
<RelativeLayout xmlns:android="http://schemas.android.
com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/text_view"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Widget ID
Old UI Testing
@MediumTest
public void testClickMeButton_clickButtonAndExpectInfoText() {
// get Object
Button mClickMeButton= (Button)mClickFunActivity.findViewById(R.id.button);
TextView mInfoTextView= (Button)mClickFunActivity.findViewById(R.id.text);
// expected text
String expectedInfoText = mClickFunActivity.getString(R.string.info_text);
// click button
TouchUtils.clickView(this, mClickMeButton);
// check
assertTrue(View.VISIBLE == mInfoTextView.getVisibility());
assertEquals(expectedInfoText, mInfoTextView.getText());
}
Test code w/o Espresso
● test for text object ,if click button
UI Testing w/ Espresso
@MediumTest
public void testClickMeButton_clickButtonAndExpectInfoText() {
// click button
onView(withId(R.id.button)).perform(click());
// check
onView(withId(R.id.text)).check(matches(isDisplayed(),
withText(R.string.info_text)));
}
Test code w/ Espresso
● test for text object ,if click button
Only 2 Lines !! OMG!!
Assertion
onView(withId(R.id.button)).
perform(click())
check(matches(isDisplayed()));
Select view -> perform -> check
ViewAction
ViewMatcher
ViewAssertion
Esprsso CheatSheet
● onView()
○ pick up view object
● onData()
○ pick up data(for List)
● intended,intending
○ check Intent Data
We can use many
Matcher methods.
not enough method...
We want to check ...
● inRoot
○ pick up view on the other Window
● Check
○ text color
○ hint text
● Other
○ wait for display
Original Matcher method
public static Matcher<View> withTextHintColor(final int resourceId) {
return new BoundedMatcher<View, TextView>(TextView.class) {
:
:
:
};
}
We can make matcher method which check
test.
ex) Toast Window
public static Matcher<Root> isToast() {
return new TypeSafeMatcher<Root>() {
@Override
public boolean matchesSafely(Root root) {
int type = root.getWindowLayoutParams().get().type;
if ((type == WindowManager.LayoutParams.TYPE_TOAST)) {
IBinder windowToken = root.getDecorView().getWindowToken();
IBinder appToken = root.getDecorView().getApplicationWindowToken();
if (windowToken == appToken) {
// windowToken == appToken means this window isn't contained by any other windows.
// if it was a window for an activity, it would have TYPE_BASE_APPLICATION.
return true;
}
}
return false;
}
};
}
Toast window Matcher.
(We have to know the Android Frameworks)
● MUST do TDD
● Android has Test Framework
● We use "Android Testing Support Library"
○ test helper libary
● Make Matchers.
Note : "MUST": RFC2119
Thank you !!

More Related Content

Similar to JUnit for android

Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross ...
Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross ...Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross ...
Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross ...
Microsoft Developer Network (MSDN) - Belgium and Luxembourg
 
Android Test Driven Development & Android Unit Testing
Android Test Driven Development & Android Unit TestingAndroid Test Driven Development & Android Unit Testing
Android Test Driven Development & Android Unit Testing
mahmoud ramadan
 
HKG15-411: Browser Testing Framework for LHG
HKG15-411: Browser Testing Framework for LHGHKG15-411: Browser Testing Framework for LHG
HKG15-411: Browser Testing Framework for LHG
Linaro
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
anistar sung
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
Ortus Solutions, Corp
 
Android Made Simple
Android Made SimpleAndroid Made Simple
Android Made Simple
Gabriel Dogaru
 
Testing in JavaScript - August 2018 - WebElement Bardejov
Testing in JavaScript - August 2018 - WebElement BardejovTesting in JavaScript - August 2018 - WebElement Bardejov
Testing in JavaScript - August 2018 - WebElement Bardejov
Marian Rusnak
 
Exploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptExploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScript
wesley chun
 
Android developer fundamentals training overview Part II
Android developer fundamentals training overview Part IIAndroid developer fundamentals training overview Part II
Android developer fundamentals training overview Part II
Yoza Aprilio
 
codeduiws-130507074566782958-phpapp02.pdf
codeduiws-130507074566782958-phpapp02.pdfcodeduiws-130507074566782958-phpapp02.pdf
codeduiws-130507074566782958-phpapp02.pdf
Patiento Del Mar
 
Coded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui testCoded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui test
Omer Karpas
 
Advanced Coded UI Testing
Advanced Coded UI TestingAdvanced Coded UI Testing
Advanced Coded UI Testing
Shai Raiten
 
Robotium - sampath
Robotium - sampathRobotium - sampath
Robotium - sampath
Sampath Muddineni
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats Bryntse
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
Peter Arato
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Guillaume Laforge
 
Productivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioProductivity Enhencement with Visual Studio
Productivity Enhencement with Visual Studio
Ahasan Habib
 
Plone testingdzug tagung2010
Plone testingdzug tagung2010Plone testingdzug tagung2010
Plone testingdzug tagung2010
Timo Stollenwerk
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
pleeps
 

Similar to JUnit for android (20)

Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross ...
Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross ...Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross ...
Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross ...
 
Android Test Driven Development & Android Unit Testing
Android Test Driven Development & Android Unit TestingAndroid Test Driven Development & Android Unit Testing
Android Test Driven Development & Android Unit Testing
 
HKG15-411: Browser Testing Framework for LHG
HKG15-411: Browser Testing Framework for LHGHKG15-411: Browser Testing Framework for LHG
HKG15-411: Browser Testing Framework for LHG
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
 
Android Made Simple
Android Made SimpleAndroid Made Simple
Android Made Simple
 
Testing in JavaScript - August 2018 - WebElement Bardejov
Testing in JavaScript - August 2018 - WebElement BardejovTesting in JavaScript - August 2018 - WebElement Bardejov
Testing in JavaScript - August 2018 - WebElement Bardejov
 
Exploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptExploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScript
 
Android developer fundamentals training overview Part II
Android developer fundamentals training overview Part IIAndroid developer fundamentals training overview Part II
Android developer fundamentals training overview Part II
 
codeduiws-130507074566782958-phpapp02.pdf
codeduiws-130507074566782958-phpapp02.pdfcodeduiws-130507074566782958-phpapp02.pdf
codeduiws-130507074566782958-phpapp02.pdf
 
Coded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui testCoded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui test
 
Advanced Coded UI Testing
Advanced Coded UI TestingAdvanced Coded UI Testing
Advanced Coded UI Testing
 
Robotium - sampath
Robotium - sampathRobotium - sampath
Robotium - sampath
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
Productivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioProductivity Enhencement with Visual Studio
Productivity Enhencement with Visual Studio
 
Plone testingdzug tagung2010
Plone testingdzug tagung2010Plone testingdzug tagung2010
Plone testingdzug tagung2010
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 

More from baroqueworksdev

デザイン領域へiOS / Android開発
デザイン領域へiOS / Android開発デザイン領域へiOS / Android開発
デザイン領域へiOS / Android開発
baroqueworksdev
 
Team Development for iOS / Android
Team Development for iOS / Android Team Development for iOS / Android
Team Development for iOS / Android
baroqueworksdev
 
Firebase analytics for_android _ i_os
Firebase analytics for_android _ i_osFirebase analytics for_android _ i_os
Firebase analytics for_android _ i_os
baroqueworksdev
 
Android m finger print(public)
Android m finger print(public)Android m finger print(public)
Android m finger print(public)
baroqueworksdev
 
Leak canaryで メモリリーク調査
Leak canaryで メモリリーク調査Leak canaryで メモリリーク調査
Leak canaryで メモリリーク調査
baroqueworksdev
 
自動テストとJenkinsの活用 公開版
自動テストとJenkinsの活用 公開版自動テストとJenkinsの活用 公開版
自動テストとJenkinsの活用 公開版
baroqueworksdev
 
Sns連携アプリの準備
Sns連携アプリの準備Sns連携アプリの準備
Sns連携アプリの準備baroqueworksdev
 
Firefox勉強会 2nd gigs_資料
Firefox勉強会 2nd gigs_資料Firefox勉強会 2nd gigs_資料
Firefox勉強会 2nd gigs_資料baroqueworksdev
 
KeonとPeakを買ってみた
KeonとPeakを買ってみたKeonとPeakを買ってみた
KeonとPeakを買ってみた
baroqueworksdev
 

More from baroqueworksdev (9)

デザイン領域へiOS / Android開発
デザイン領域へiOS / Android開発デザイン領域へiOS / Android開発
デザイン領域へiOS / Android開発
 
Team Development for iOS / Android
Team Development for iOS / Android Team Development for iOS / Android
Team Development for iOS / Android
 
Firebase analytics for_android _ i_os
Firebase analytics for_android _ i_osFirebase analytics for_android _ i_os
Firebase analytics for_android _ i_os
 
Android m finger print(public)
Android m finger print(public)Android m finger print(public)
Android m finger print(public)
 
Leak canaryで メモリリーク調査
Leak canaryで メモリリーク調査Leak canaryで メモリリーク調査
Leak canaryで メモリリーク調査
 
自動テストとJenkinsの活用 公開版
自動テストとJenkinsの活用 公開版自動テストとJenkinsの活用 公開版
自動テストとJenkinsの活用 公開版
 
Sns連携アプリの準備
Sns連携アプリの準備Sns連携アプリの準備
Sns連携アプリの準備
 
Firefox勉強会 2nd gigs_資料
Firefox勉強会 2nd gigs_資料Firefox勉強会 2nd gigs_資料
Firefox勉強会 2nd gigs_資料
 
KeonとPeakを買ってみた
KeonとPeakを買ってみたKeonとPeakを買ってみた
KeonとPeakを買ってみた
 

Recently uploaded

Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 

Recently uploaded (20)

Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 

JUnit for android

  • 2. ● MUST do TDD ● Android has Test Framework ● We'll use "Android Testing Support Library" ○ test helper libary まとめ Note : "MUST": RFC2119
  • 3. Android Test Policy Debugging and testing in Android Studio (Ep 4, Android Studio) https://youtu.be/2I6fuD20qlY
  • 4. Test driven development Test First Test MUST run on Master branch!!
  • 5. Test fundamental in Android Android Test frameworks
  • 6. 2 type of JUnit ● Normal JUnit (3.0 , 4.0) ○ running on JVM ○ Java class , module test ● Android JUnit (3.0 , 4.0) ○ running on Adroid Device(Emulator) ○ UI Testing
  • 8. UI Testing Tools ● Android Studio ● Espresso(android-test-kit, for Google)
  • 9. Layout file Layout file to configure the screen. <RelativeLayout xmlns:android="http://schemas.android. com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/text_view" android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout> Widget ID
  • 10. Old UI Testing @MediumTest public void testClickMeButton_clickButtonAndExpectInfoText() { // get Object Button mClickMeButton= (Button)mClickFunActivity.findViewById(R.id.button); TextView mInfoTextView= (Button)mClickFunActivity.findViewById(R.id.text); // expected text String expectedInfoText = mClickFunActivity.getString(R.string.info_text); // click button TouchUtils.clickView(this, mClickMeButton); // check assertTrue(View.VISIBLE == mInfoTextView.getVisibility()); assertEquals(expectedInfoText, mInfoTextView.getText()); } Test code w/o Espresso ● test for text object ,if click button
  • 11. UI Testing w/ Espresso @MediumTest public void testClickMeButton_clickButtonAndExpectInfoText() { // click button onView(withId(R.id.button)).perform(click()); // check onView(withId(R.id.text)).check(matches(isDisplayed(), withText(R.string.info_text))); } Test code w/ Espresso ● test for text object ,if click button Only 2 Lines !! OMG!!
  • 13. Esprsso CheatSheet ● onView() ○ pick up view object ● onData() ○ pick up data(for List) ● intended,intending ○ check Intent Data We can use many Matcher methods.
  • 14. not enough method... We want to check ... ● inRoot ○ pick up view on the other Window ● Check ○ text color ○ hint text ● Other ○ wait for display
  • 15. Original Matcher method public static Matcher<View> withTextHintColor(final int resourceId) { return new BoundedMatcher<View, TextView>(TextView.class) { : : : }; } We can make matcher method which check test.
  • 16. ex) Toast Window public static Matcher<Root> isToast() { return new TypeSafeMatcher<Root>() { @Override public boolean matchesSafely(Root root) { int type = root.getWindowLayoutParams().get().type; if ((type == WindowManager.LayoutParams.TYPE_TOAST)) { IBinder windowToken = root.getDecorView().getWindowToken(); IBinder appToken = root.getDecorView().getApplicationWindowToken(); if (windowToken == appToken) { // windowToken == appToken means this window isn't contained by any other windows. // if it was a window for an activity, it would have TYPE_BASE_APPLICATION. return true; } } return false; } }; } Toast window Matcher. (We have to know the Android Frameworks)
  • 17. ● MUST do TDD ● Android has Test Framework ● We use "Android Testing Support Library" ○ test helper libary ● Make Matchers. Note : "MUST": RFC2119