android testing - pic.huodongjia.com€¦ · s ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int...

of 38 /38
Android Testing Gemini https://github.com/geminiwen

Upload: others

Post on 27-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Android TestingGemini

https://github.com/geminiwen

Page 2: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

About Me• Gemini

• SegmentFault for Android

• SegmentFault

• Android

• engine.io

Page 3: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

• Mockito

• Dagger

• CI

Page 4: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

….

Page 5: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

• Unit Test

• UI

Page 6: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

UI

Page 7: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

• 100%

Page 8: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

int add (int a, int b) { return a + b;

}

assertEquals(add(1,2), 3 );

Page 9: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Page 10: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

void job1(); void job2(); int job3();

assertEquals(job3_result, job3());

Page 11: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

UI

Page 12: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Android Testing Framework

Espresso

Page 13: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

@Test public void greeterSaysHello() { onView(withId(R.id.name_field)) .perform(typeText(“Steve"));

onView(withId(R.id.greet_button)) .perform(click());

onView(withText("Hello Steve!")) .check(matches(isDisplayed())); }

Page 14: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

UI

• UI

• UI

Page 15: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 16: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 17: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 18: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 19: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 20: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

void business()

callback

IdleResource By

Espresso

Page 21: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Idle Resource

@Override boolean isIdleNow();

ResourceCallback.onTransitionToIdle();

okhttp3-idleresource

Page 22: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Mock

• Mock Object

• Mock Http

Page 23: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Mockito

• model UI

• model

Page 24: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

@Test public void test1() { // mock MyClass test = Mockito.mock(MyClass.class);

// getUniqueId() when(test.getUniqueId()).thenReturn(43);

// mock assertEquals(test.getUniqueId(), 43); }

Page 25: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

OkHttp MockWebServer

Page 26: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Mock Object

• Dagger2 —— DI

Page 27: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Dagger Components

• Module ——

• Component ——

• @Inject ——

Page 28: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Module Source1

Component

Module Source2

@Inject

Page 29: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 30: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 31: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 32: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 33: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

App with inject point

Components

Module

TestModule

Page 34: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Dagger Management

• User Store

• Database Instance (SQLite)

• Retrofit Instance

Page 35: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Gitlab CI

Page 36: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());
Page 37: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

• TDD ——

Page 38: Android Testing - pic.huodongjia.com€¦ · S ½ Þ _ Ü ) r ñ Ó f void job1(); void job2(); int job3(); assertEquals(job3_result, job3());

Thanks!