Giter Club home page Giter Club logo

androidtestktx's Introduction

Android Test KTX

Version

This library is a collection of Kotlin extension and infix functions made to increase the readability and decrease the boilerplate of Espresso and UIAutomator matchers and actions.

It is inteded to work well with RobotPattern, as the naming convention of the functions assume to have some sort of semantical context on the call site.

This is a Work In Progress, and contributions are highly welcomed. For the future plans of library development, please check the Wiki.

Simple test example:

@Test
fun shouldLoginUser_whenStartingTheAppForTheFirstTime() {
  withLoginRobot {
    loginDemoUser()
  } andThen {
    acceptThePermissions
  } andThenVerifyThat {
    userIsLoggedIn()
  }
}

Show me the code

In order to login the user properly, we have to find a login button, and username and password fields.

Unified Espresso/UIAutomator syntax - KTX

class MainActivityTest {
    
    @Test
    fun shouldLoginDemoUser(){
        typeText("dummyUsername") into text(R.id.activityLoginEditTextUsername)
        typeText("dummyPassword") into text(R.id.activityLoginEditTextPassword)
        click on button(R.id.activityLoginBtnLogin)
        
        MainActivity::class verifyThat { itIsDisplayed() }
    }
}

In the old fashion way, we'd do something like this:

Espresso syntax

class MainActivityTest {
    
    @Test
    fun shouldLoginDemoUser(){
        onView(withId(R.id.activityLoginEditTextUsername)).perform(typeText("dummyUsername"))
        onView(withId(R.id.activityLoginEditTextPassword)).perform(typeText("dummyPassword"))
        onView(withId(R.id.activityLoginBtnLogin)).perform(click())
        
        Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name))
    }
}

UIAutomator syntax

class MainActivityTest {
    
    @Test
    fun shouldLoginDemoUser(){
        val instrumentation = InstrumentationRegistry.getInstrumentation()
        val uiDevice = UiDevice.getInstance(instrumentation)
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        
        val usernameSelector = UiSelector().resourceId(appContext.resources.getResourceName(
                R.id.activityLoginEditTextUsername
            )
        )
        val usernameTextField = uiDevice.findObject(usernameSelector)
        usernameTextField.text = "dummyUsername"
        val passwordSelector = UiSelector().resourceId(appContext.resources.getResourceName(
                R.id.activityLoginEditTextPassword
            )
        )
        val passwordTextField = uiDevice.findObject(passwordSelector)
        passwordTextField.text = "dummyPassword"
        val loginButtonSelector = UiSelector().resourceId(appContext.resources.getResourceName(
                R.id.activityLoginBtnLogin
            )
        )
        val loginButton = uiDevice.findObject(loginButtonSelector)
        loginButton.click()
        
        Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name))
    }
}

Usage

In the build.gradle file of your app module, put this line into the dependencies:

androidTestImplementation 'de.codecentric:androidtestktx:0.9.0'

Make sure that in the project level build.gradle file, you're using the JCenter as repository source:

allprojects {
  repositories {
    ...
    jcenter()
  }
}

LICENSE

Apache 2.0

androidtestktx's People

Contributors

bajicdusko avatar spatenotte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidtestktx's Issues

Cover the CLICK/PRESS ViewActions

Implement the missing extensions for the CLICK/PRESS part of Espresso cheat sheet.

Acceptance criteria:

  • Click/Press actions should be implemented for both, Espresso and UIAutomator.
  • Tests in the demo app should be written for both libraries (and passing)

Connect the CI pipeline

We should set up the CI pipeline somewhere, where we'll execute all tests from the demo in order to verify that new implementations are working properly. Let's not forget to wire the testing results with the test tag in the README file.

Cover the UI PROPERTIES of ViewMatchers

Implement the missing extensions for the UI PROPERTIES part of the Espresso cheat sheet, section ViewMatchers.

Acceptance criteria:

  • UI PROPERTIES should be implemented for both, Espresso and UIAutomator.
  • Tests in the demo app should be written for both libraries (and passing)

Cover the GESTURES ViewActions

Implement the missing extensions for the GESTURES part or Espresso cheat sheet.

Acceptance criteria:

  • Gestures should be implemented for both, Espresso and UIAutomator.
  • Tests in the demo app should be written for both libraries (and passing)

Cover the USER PROPERTIES ViewMatchers

Implement the missing extensions for the USER PROPERTIES part of the Espresso cheat sheet, section ViewMatchers.

Acceptance criteria:

  • USER PROPERTIES should be implemented for both, Espresso and UIAutomator.
  • Tests in the demo app should be written for both libraries (and passing)

Add a test status label

On top of the README file, we should have a test status tag, showing whether the tests are passing or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.