Testing

Android Test Framework

Android Test Framework

  • Incluído na SDK do Android
  • Baseado no JUnit 3
  • Rodam em devices ou emuladores

Robotium

  • Utilizar apenas a ATFramework é trabalhoso, maçante;
  • Considerado uma extensão do ATFramework;
  • Sua classe principal é a Solo.

dependencies {

    compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
}

android {
   sourceSets {
     androidTest {
       java.srcDirs = ['src/androidTest/java']
     }        
   }
 }

"Running tests on an Android emulator or device is slow! Building, deploying, and launching the app often takes a minute or more. That's no way to do TDD. There must be a better way."

"Tests run inside the JVM on your workstation in seconds."

"Robolectric makes this possible by rewriting Android SDK classes as they're being loaded and making it possible for them to run on a regular JVM."

Configurar o Android Studio ainda está muito doloroso...

https://github.com/mutexkid/android-studio-robolectric-example

Problemas com support v7

https://github.com/klinker41/Robolectric-AppCompat-Example

Nada certo!

A esperança!

Android JUnit Runner

The AndroidJUnitRunner class is a JUnit test runner that lets you run JUnit 3 or JUnit 4-style test classes on Android devices, including those using the Espresso and UI Automator testing frameworks. The test runner handles loading your test package and the app under test to a device, running your tests, and reporting test results. This class replaces the InstrumentationTestRunner class, which only supports JUnit 3 tests.

UI Automator

The UI Automator testing framework provides a set of APIs to build UI tests that perform interactions on user apps and system apps. The UI Automator APIs allows you to perform operations such as opening the Settings menu or the app launcher in a test device. The UI Automator testing framework is well-suited for writing black box-style automated tests, where the test code does not rely on internal implementation details of the target app.

Espresso

The Espresso testing framework provides a set of APIs to build UI tests to test user flows within an app. These APIs let you write automated UI tests that are concise and that run reliably. Espresso is well-suited for writing white box-style automated tests, where the test code utilizes implementation code details from the app under test.

Exemplos

Minha implementação de UnitTest e Espresso

https://github.com/ricardolonga/todo

Exemplos da Google c/ UnitTest, Espresso e UIAutomator

https://github.com/googlesamples/android-testing

Promete AppCompat v7 & Robolectric

https://github.com/freezy/android-seed

Mais ferramentas

Continuous Integration

https://app.greenhouseci.com/
https://ship.io/

https://circleci.com/

https://appthwack.com/

Desenv. de apps móveis para Android (Testing)

By Ricardo Longa

Desenv. de apps móveis para Android (Testing)

  • 1,448