UI
Automator
Becomes
Friendly
with
Espresso 2015.11.17
@sumio_tym
(TOYAMA
Sumio) Roppongi.aar
#2 Portions
of
this
presentation
are
reproduced
from
work
created
and
shared
by
the
Android
Open
Source
Project[1]
and
used
according
to
terms
described
in
the
Creative
Commons
2.5
Attribution
License[2].
[1]
http://code.google.com/policies.html
[2]
http://creativecommons.org/licenses/by/2.5/
About
Me • TOYAMA
Sumio
(֎ࢁ७ੜ)
@sumio_tym
(twitter),
@sumio
(github)
• NTT
Software
Corporation
– Provide
technical
assistance
to
Android
Projects
• Private
activities
– STAR
(Software
Test
Automation
Research
Group
Jp)
– Some
articles
in
@IT
related
to
uiautomator/Appium:
ʮεϚϗ͚ແྉγεςϜςετࣗಈԽπʔϧʯ
http://www.atmarkit.co.jp/ait/kw/smapho_testtool.html
2
Overview • Architecture
of
UI
Automator
is
changed
into
Instrumentation
Test
as
of
ver.
2.x.
• The
change
makes
you
write
a
test
method
in
mixture
of
Espresso
and
UI
Automator.
• We
show
a
concrete
example
in
this
talk.
3
Instrumentation
Test
(Android) 5
• Both
application
under
test
(AUT)
and
test
package:
– run
on
the
same
process.
– must
be
signed
by
the
same
certificate.
• The
test
package
can
examine
the
AUT
deeply.
(e.g.
fields
of
Activity)
Quoted
from
http://developer.android.com/intl/ja/tools/testing/testing_android.html
Espresso 6
• Testing
framework
for
writing
UI
tests
– Single
app
testing
– White-‐box
style
testing
(Can
access
the
interior
of
the
AUT)
• Architecture:
Instrumentation
test
• Supported
API
level:
≥8
• Easier
to
write
Quoted
from
http://developer.android.com/intl/ja/training/testing/ui-‐testing/espresso-‐testing.html
UI
Automator 7
• Testing
framework
for
writing
UI
tests
– Cross-‐app
testing
– Black-‐box
style
testing
(Can
not
access
the
interior
of
the
AUT)
• Architecture:
– Specialized
architecture
for
UI
Automator
(as
of
1.x)
– Instrumentation
test
(as
of
2.x)
• Supported
API
level:
– ≥16
(as
of
1.x)
– ≥18
(as
of
2.x)
• More
complicated
to
write
UI
Automator
(cont.) 8
• See
also
"Notable
Changes
in
UI
Automator
2.0"
(ABC
2015
Summer)
https://speakerdeck.com/sumio/notable-‐changes-‐in-‐ui-‐automator-‐2-‐dot-‐0
Quoted
from
http://developer.android.com/intl/ja/training/testing/ui-‐testing/uiautomator-‐testing.html
• Now,
both
Espresso
and
UI
Automator
are
based
on
Instrumentation
Test.
• So,
you
can
write
a
test
method
in
a
mixture
of
them.
• That
widen
a
testable
area:
– Use
Espresso
for
AUT
(main
purpose)
– Use
UI
Automator
for
other
apps
(e.g.
launched
by
the
AUT)
9
UI
Automator
Becomes
Friendly
with
Espresso
Test
Class 12
@RunWith(AndroidJUnit4.class) public class MainActivityTest { @Rule public ActivityTestRule activityRule = new ActivityTestRule<>(MainActivity.class); private UiDevice uiDevice; @Before public void setUp() { uiDevice = UiDevice. getInstance(InstrumentationRegistry.getInstrumentation()); } // YOUR TEST METHOD HERE } for
Instrumentation
Test for
UI
Automator
Scenario 15
1. (In
AUT)
Tap
"ઃఆΞϓϦΛදࣔ͢Δ"
2. (In
Settings
App)
Tap
"ͱ࣌ࠁ"
3. Turn
on/off
"24࣌ؒදࣔ"
4. Press
the
back
key
twice
5. (In
AUT)
Enter
"Hello
World!"
into
the
text
box
by
using
UI
Automator
Wrap
Up 18
• UI
Automator
becomes
friendly
with
Espresso
– You
can
write
a
test
method
in
a
mixture
of
them.
• Enables
you
to
write
a
cross-‐app
test
more
easily
by
using
mainly
Espresso.
• A
concrete
example
is
available
from
https://github.com/sumio/UiAutomatorEspressoSample
Thank
you
!