Top Banner
Espresso 101: Introdução a UI Testing Pedro Salomão @ppgsalomao [email protected] / [email protected]
27

Espresso 101: Introdução a UI Testing

Jan 21, 2017

Download

Technology

Onyo
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Espresso 101: Introdução a UI Testing

Espresso 101:Introdução a UI Testing

Pedro Salomão @ppgsalomao

[email protected] / [email protected]

Page 2: Espresso 101: Introdução a UI Testing

#whoami

Page 3: Espresso 101: Introdução a UI Testing

Objetivos

Page 4: Espresso 101: Introdução a UI Testing

Objetivos1. Onde entram as diversas ferramentas de teste;

2. O que são Testes de Interface do Usuário;

3. Como definir o que testar;

4. Como integrar o Espresso ao meu projeto;

5. Como escrever o meu primeiro teste de UI;

6. [BÔNUS] Demo.

Page 5: Espresso 101: Introdução a UI Testing

Ferramentas para Teste

Page 6: Espresso 101: Introdução a UI Testing

Camadas da Aplicação

USUÁRIO APK INTERNETInterfaceGráfica

Page 7: Espresso 101: Introdução a UI Testing

Ferramentas para Teste

Robolectric API 16+

JVM

Espresso API 8+ Robotium Calabash Selendroid

Instrumentation API 1+

Android Platform

Appium

UIAutomatorAPI 16+

UIAutomationAPI 18+

Page 8: Espresso 101: Introdução a UI Testing

Ferramentas para Teste

Robolectric API 16+

JVM

EspressoAPI 8+ Robotium Calabash Selendroid

Instrumentation API 1+

Android Platform

Appium

UIAutomatorAPI 16+

UIAutomationAPI 18+

Page 9: Espresso 101: Introdução a UI Testing

Camadas da Aplicação

USUÁRIOESPRESSO APK INTERNETInterface

Gráfica

Page 10: Espresso 101: Introdução a UI Testing

Testes de Interface

Page 11: Espresso 101: Introdução a UI Testing

Testes de Interface1. O que devo testar?

2. Qual o escopo de um teste (método)?

3. Posso testar fluxos completos?

4. E como funciona o estado da aplicação?

5. O que é um Mock e por que é importante?

Page 12: Espresso 101: Introdução a UI Testing
Page 13: Espresso 101: Introdução a UI Testing

Espresso

Processo

APK Test APK

Espresso

Page 14: Espresso 101: Introdução a UI Testing

Vamos falar de código?!

Page 15: Espresso 101: Introdução a UI Testing

Integrando o Espresso

Page 16: Espresso 101: Introdução a UI Testing

Integrando o Espresso1. Adicionar no build.gradle, em dependencies:

2. Adicionar no build.gradle, em android.defaultConfig:

compile 'com.android.support:support-annotations:23.1.1' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile 'com.android.support.test:runner:0.4.1'

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

fonte: https://google.github.io/android-testing-support-library/docs/espresso/setup/index.html

Page 17: Espresso 101: Introdução a UI Testing

Escrevendo o Teste

Page 18: Espresso 101: Introdução a UI Testing

Espresso - Asserts

onView( ViewMatcher ) .perform( ViewAction )

.check( ViewAssertion )

fonte: https://google.github.io/android-testing-support-library/docs/espresso/cheatsheet/index.html

Page 19: Espresso 101: Introdução a UI Testing

ViewMatcherDois usos básicos:

• Encontrar uma view (onView) • Verificar uma condição da View (matches)

Exemplos:

• withId( … ) • withText( … ) • isDisplayed()

Page 20: Espresso 101: Introdução a UI Testing

ViewActionPermite executar ações na tela.

Exemplos:

• click() • scrollTo( … ) • typeText( … )

Page 21: Espresso 101: Introdução a UI Testing

ViewAssertionPermite verificar uma determinada propriedade.

Exemplos:

• matches( Matcher ) • doesNotExists( … ) • typeText( … )

Observação: doesNotExists() != isNotDisplayed()

Page 22: Espresso 101: Introdução a UI Testing

Criando um testePassos para criar um Teste usando Espresso:

• Adicionar a anotação do JUnit na classe. • Adicionar uma Rule para a Activity a ser testada. • Criar os métodos de teste.

Page 23: Espresso 101: Introdução a UI Testing

Exemplo

@RunWith(AndroidJUnit4.class) @LargeTest public class HelloWorldEspressoTest {

@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);

@Test public void listGoesOverTheFold() { onView(withText("Hello world!”)) .check(matches(isDisplayed())); } }

Page 24: Espresso 101: Introdução a UI Testing

DEMO

Page 25: Espresso 101: Introdução a UI Testing

Links ÚteisSite da Google para Android Testinghttps://google.github.io/android-testing-support-library/

Código do Demo de Espressohttps://github.com/ppgsalomao/espresso-examples

GTAC 2014: Espresso, Spoon, Wiremock, Oh my!https://www.youtube.com/watch?v=-xQCNf_5NNM

Droidcon NYC 2015 - Advanced Android Espressohttps://www.youtube.com/watch?v=GlPn60-_txk

Page 26: Espresso 101: Introdução a UI Testing

Dúvidas?