Tasting
Tasting is Android library which simplifies writing UI tests and wraps Spoon screen capturing, so you can take screenshots in your tests and see them in HTML report aftewards.
Installation
Add JitPack and Spoon plugin to your root build.gradle
:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
...
classpath "com.jaredsburrows:gradle-spoon-plugin:1.0.0"
}
}
Apply Spoon plugin:
apply plugin: 'spoon'
Configure Spoon:
spoon {
debug = true
noAnimations = true
grantAllPermissions = true
}
Add the dependencies you need:
androidTestImplementation 'com.github.thefuntasty:tasting:latestVersion'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.squareup.spoon:spoon-client:1.7.1'
Usage
Implementation
- Create
BaseScenario
class (extendingScenario
) inandroidTest/
directory - Override
beforeSetUp()
method where you can change bot settings or delete persistent data (to make every test start from the same initial state) - Override
afterSetUp()
method where you can make bot wait for app to load
open class BaseScenario : Scenario() {
override fun beforeSetUp() {
bot.scrollThreshold = SCROLL_THRESHOLD
bot.viewTimeout = VIEW_TIMEOUT
//delete persistence here
}
override fun afterSetUp() {
bot.waitForId(bot.getViewId(R.id.login_button), LAUNCH_TIMEOUT)
}
}
- Create eg.
AccountScenario
class (extendingBaseScenario
) which will contain all tests regarding user account
@RunWith(AndroidJUnit4::class)
class SampleScenario : BaseScenario() {
@Test
fun login() {
bot.writeById(bot.getViewId(R.id.login_field), bot.email)
bot.writeById(bot.getViewId(R.id.password_field), bot.getRandomString(21))
bot.tapById(bot.getViewId(R.id.login_button))
bot.presentById(bot.getViewId(R.id.login_check))
bot.takeScreenshot("loggedIn")
}
}
Running tests
- Open terminal at your Android project directory
- Run
./gradlew spoonDebug
(or specify any other build variant eg.spoonClient
)
Checking results
- You can see test progress and result in terminal window
- After finishing all tests, interactive HTML test report is generated in your project directory (
build/spoon-output/...
), including screenshots you took withbot.takeScreenshot()
method. Screenshot is also taken automatically on test failure, so you can find out what went wrong easier.
Contributors
Current maintainer and main contributor is Adam Svoboda, adam.svoboda@futured.app.
License
Tasting is available under the MIT license. See the LICENSE for more information.