The Developer Preview for Android 11 is now available; test it out and share your feedback.

ComposeBenchmarkScope

interface ComposeBenchmarkScope<T> : ComposeExecutionControl
androidx.ui.test.ComposeBenchmarkScope

Test scope accessible from benchmarks. Provides extended set of hooks for compose benchmarking.

Summary

Public methods

abstract Unit

Instantiates the current ComposeTestCase in order to perform benchmarks on it.

abstract Unit

Disposes the content and destroys the current ComposeTestCase.

abstract Unit

To be run in benchmark.

abstract Unit

Final step after draw.

abstract Unit

Preparation for draw.

abstract Unit

Emits the content.

abstract T

Returns the current instantiated ComposeTestCase.

abstract Unit

Invalidates the view / compose hierarchy.

abstract Unit
measureWithSpec(widthSpec: Int, heightSpec: Int)

Calls measureWithSpec on the underlying view.

abstract Unit

Request layout on the underlying view.

Inherited functions

Extension functions

From androidx.ui.test
Unit

Sets up the content.

Inherited extension functions

From androidx.ui.test
Unit

Performs recomposition and asserts that there were some pending changes.

Unit

Asserts that last recomposition had some changes.

Unit

Asserts that last recomposition had no some changes.

Unit

Assert that the underlying view under test has a positive size.

Unit

Performs recomposition and asserts that there were some pending changes.

Unit

Performs the given amount of frames and asserts that there are no changes pending afterwards.

Int

Runs frames until there are no changes pending.

Unit

Performs recomposition and asserts that there were some pending changes.

From androidx.compose
operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Inherited properties

Public methods

createTestCase

abstract fun createTestCase(): Unit

Instantiates the current ComposeTestCase in order to perform benchmarks on it.

This is normally executed as part of setupContent.

Do not measure this in benchmark.

disposeContent

abstract fun disposeContent(): Unit

Disposes the content and destroys the current ComposeTestCase.

This is typically needed when benchmarking the first content setup or composition.

draw

abstract fun draw(): Unit

To be run in benchmark. Call drawPrepare before and drawFinish after.

drawFinish

abstract fun drawFinish(): Unit

Final step after draw. Do not measure this in benchmark.

drawPrepare

abstract fun drawPrepare(): Unit

Preparation for draw. Do not measure this in benchmark.

emitContent

abstract fun emitContent(): Unit

Emits the content. This and createTestCase are by default called by first invocation of doFrame. However this is useful in case you need to benchmark the first composition.

If you want to call this multiple times, make sure you call disposeContent and createTestCase in between. If you don't need to measure this but need to setup the content consider using setupContent.

getTestCase

abstract fun getTestCase(): T

Returns the current instantiated ComposeTestCase.

Make sure you called setupContent or createTestCase before calling this.

invalidateViews

abstract fun invalidateViews(): Unit

Invalidates the view / compose hierarchy. This is should typically not be needed if your changes invalidate view by default.

measureWithSpec

abstract fun measureWithSpec(
    widthSpec: Int,
    heightSpec: Int
): Unit

Calls measureWithSpec on the underlying view.

requestLayout

abstract fun requestLayout(): Unit

Request layout on the underlying view. This is should typically not be needed if your changes invalidate layout by default.