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).
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