Skip to content

A TestRule for android instrumentation test to measure ui smoothness

Notifications You must be signed in to change notification settings

yangweigbh/UiScoreRule

Repository files navigation

UiScoreRule

60fps is critical metrics that Ui render smoothly for the end user, so it's important to monitor the ui performance in our automation Ui test. UiScoreRule is an android instrumentation test rule to measure ui smoothness, the test rule will collect the frame stats during the test run, and output the score calculated based on this

Setup:

add it in your root build.gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

in your app build.gradle

android {
    ...
    defaultConfig {
        ...
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments 'listener': 'com.github.yangweigbh.uiscore.TestListener'
    }
}

dependencies {
    androidTestImplementation 'com.github.yangweigbh:UiScoreRule:1.1'
}

Usage

In the Instrumentation test, add UiScoreRule in your test class

public class MainActivityTest {
    @Rule
    public UiScoreRule mUiScoreRule = new UiScoreRule();

    ....
}

Annotate @PerfTest to the test that you want to measure ui score

public class MainActivityTest {
    @Rule
    public UiScoreRule mUiScoreRule = new UiScoreRule();

    @Test
    @PerfTest
    public void scrollRecyclerView() {
        .....
    }
}

the output will be print into logcat like below, you can use UiScore TAG to filter in the logcat:

2019-11-24 22:13:14.821 20850-20941/com.github.yangweigbh.uiscorerule I/UiScore: Result: 
    ┌───────────────────────────────────┬────────────┬──────────────────────┬───────────────────┬─────────────────────────┬─────────────────┐
    │             Test Name             │Total Frames│Average frame duration│Frame duration 99th│Bad frames standDeviation│      Score      │
    ├───────────────────────────────────┼────────────┼──────────────────────┼───────────────────┼─────────────────────────┼─────────────────┤
    │MainActivityTest.scrollRecyclerView│    4344    │         9.04         │       21.17       │          40.61          │       96        │
    ├───────────────────────────────────┼────────────┼──────────────────────┼───────────────────┼─────────────────────────┼─────────────────┤
    │               Total               │            │                      │                   │                         │95.99999999999999│
    └───────────────────────────────────┴────────────┴──────────────────────┴───────────────────┴─────────────────────────┴─────────────────┘

About

A TestRule for android instrumentation test to measure ui smoothness

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages