Coder Social home page Coder Social logo

android-testng's Introduction

TestNG runner for Android

This is a minimal implementation of an Android Instrumentation executing unit tests based on TestNG (the best testing framework for Java).

Download

Usage

Depending on your build system, your mileage might vary, but with Gradle the only required changes to your build files should be limited to adding our repository, then declaring the dependency and modifying your testInstrumentationRunner:

// Our Bintray repository
repositories {
  maven {
    url 'http://dl.bintray.com/lemonade/maven'
  }
}

// TestNG dependency, remember to update to the latest version
dependencies {
  androidTestCompile 'de.lemona.android:android-testng:X.Y.Z'
}

// Android setup
android {
  defaultConfig {
    testInstrumentationRunner 'de.lemona.android.testng.TestNGRunner'
  }
}

Packages

The runner will ONLY look for classes in the package specified by the targetPackage entry in your AndroidManifest.xml file.

In Gradle this defaults to your application package plus ....test.

If no tests can be found, verify the parameter in the manifest of your APK.

For example in our manifest the declared package is de.lemona.android.testng, henceforth after the build processes it, all our tests will be automatically searched for in the de.lemona.android.testng.test package.

XML Suites

Test suites can also be defined using a testng.xml file from your assets directory.

This is useful when tests do not reside in the standard application package plus ....test.

One caveat, though, is that the <package /> element does not work (yet), as TestNG expects JAR files, while Android bundles everything into a DAX file.

For an example see the testng.xml file included alongside these sources.

Contexts

In order to have access to the Android's application Context please refer to the AndroidTestNGSupport utility class. The two static getContext() and getInstrumentation() methods allow retrieval of the instances.

Google Guice injection is also supported. Take a look at the GuiceInjectionTest for an example of how to configure your tests.

Options

The options to enable some features on testing are same as adb instrument. Current supported options are as below:

  • debug
  • coverage
  • coverageFile

If you need to run tests from Android Studio, please use Android Tests Configuration.

License

Licensed under the Apache License version 2

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.