Skip to content

Commit

Permalink
Merge pull request #1743 from google/av/deprecate-test-harness
Browse files Browse the repository at this point in the history
[TestHarness] Deprecate testharness
  • Loading branch information
bentrengrove authored Jan 30, 2024
2 parents 47f460a + ac06759 commit 0d0198d
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 65 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ A library which provides a way to use Android Drawables as Jetpack Compose Paint
### 📜 [Adaptive](./adaptive/)
A library providing a collection of utilities for adaptive layouts.

### 🗜 [Test Harness](./testharness/)
Utilities for testing Compose layouts.

### ⬇️ [Swipe to Refresh](./swiperefresh/) (Deprecated)
See our [Migration Guide](https://google.github.io/accompanist/swiperefresh/) for migrating to PullRefresh in Compose Material.

Expand Down Expand Up @@ -91,6 +88,9 @@ A library that enables the reuse of [MDC-Android][mdc] Material 3 XML themes, fo
### 🌏 [Web](./web/) (Deprecated)
A wrapper around WebView for basic WebView support in Jetpack Compose.

### 🗜 [Test Harness](./testharness/) (Deprecated)
Utilities for testing Compose layouts.

### 📐 [Insets](./insets/) (Deprecated & Removed)
See our [Migration Guide](https://google.github.io/accompanist/insets/) for migrating to Insets in Compose.

Expand Down
3 changes: 0 additions & 3 deletions adaptive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ dependencies {
androidTestImplementation(project(":internal-testutils"))
testImplementation(project(":internal-testutils"))

androidTestImplementation(project(":testharness"))
testImplementation(project(":testharness"))

androidTestImplementation(libs.junit)
testImplementation(libs.junit)

Expand Down

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions docs/testharness.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@

[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-testharness)](https://search.maven.org/search?q=g:com.google.accompanist)

!!! warning
**This library is deprecated, with a superseding version in androidx.compose.ui.test. The migration guide and original documentation is below.

## Migration

`DeviceConfigurationOverride` from `ui-test` is the replacement for `TestHarness`.

The top-level [`@Composable DeviceConfigurationOverride`](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#DeviceConfigurationOverride(androidx.compose.ui.test.DeviceConfigurationOverride,kotlin.Function0))
provides the same structure as `TestHarness`, applying overrides to a piece of `content` under test.

Instead of all of the overrides appearing as parameters to `TestHarness`, the
`DeviceConfigurationOverride` top-level function takes a particular implementation of the
[`fun interface DeviceConfigurationOverride`](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/DeviceConfigurationOverride).

The [built-in `DeviceConfigurationOverride`s](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/DeviceConfigurationOverride.Companion)
are available as extension methods on the companion object of `DeviceConfigurationOverride`, and
the built-in overrides cover all of the parameters of `TestHarness`.

Multiple `DeviceConfigurationOverride`s can be combined with [then](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.DeviceConfigurationOverride).then(androidx.compose.ui.test.DeviceConfigurationOverride))

## Migration steps:

1. Replace `TestHarness()` with `DeviceConfigurationOverride()` (a deprecation replacement is
available)
1. Remove the override for any argument that was previously using a default value.
Because the overrides have been split into independent overrides, the "default" behavior can
be achieved by not specifying that override.

Example: If you want to keep the current dark mode setting and not override it, instead of
querying for and specifying the current dark mode theme to apply in an override, don't apply the
`DeviceConfigurationOverride.DarkMode` override.

## Original docs

A library providing a test harness for UI components.

## Background
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ compose-ui-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
compose-ui-util = { module = "androidx.compose.ui:ui-util", version.ref = "compose" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
compose-ui-test = { module = "androidx.compose.ui:ui-test", version.ref = "compose" }
compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose" }
compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "compose" }
compose-foundation-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
Expand Down
3 changes: 0 additions & 3 deletions pager/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ dependencies {
androidTestImplementation(project(":internal-testutils"))
testImplementation(project(":internal-testutils"))

androidTestImplementation(project(":testharness"))
testImplementation(project(":testharness"))

androidTestImplementation(libs.junit)
testImplementation(libs.junit)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.DeviceConfigurationOverride
import androidx.compose.ui.test.LayoutDirection
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.assertHeightIsAtLeast
import androidx.compose.ui.test.assertLeftPositionInRootIsEqualTo
Expand All @@ -41,7 +43,6 @@ import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.height
import androidx.compose.ui.unit.width
import com.google.accompanist.testharness.TestHarness

/**
* Contains [HorizontalPager] tests. This class is extended
Expand Down Expand Up @@ -125,7 +126,9 @@ abstract class BaseHorizontalPagerTest(
userScrollEnabled: Boolean,
onPageComposed: (Int) -> Unit
) {
TestHarness(layoutDirection = layoutDirection) {
DeviceConfigurationOverride(
DeviceConfigurationOverride.LayoutDirection(layoutDirection = layoutDirection)
) {
applierScope = rememberCoroutineScope()

Box {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.DeviceConfigurationOverride
import androidx.compose.ui.test.LayoutDirection
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.assertHeightIsAtLeast
import androidx.compose.ui.test.assertLeftPositionInRootIsEqualTo
Expand All @@ -39,7 +41,6 @@ import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.height
import androidx.compose.ui.unit.width
import com.google.accompanist.testharness.TestHarness

/**
* Contains the [VerticalPager] tests. This class is extended
Expand Down Expand Up @@ -105,7 +106,9 @@ abstract class BaseVerticalPagerTest(
userScrollEnabled: Boolean,
onPageComposed: (Int) -> Unit
) {
TestHarness(layoutDirection = LayoutDirection.Ltr) {
DeviceConfigurationOverride(
DeviceConfigurationOverride.LayoutDirection(layoutDirection = LayoutDirection.Ltr)
) {
applierScope = rememberCoroutineScope()

Box {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")

package com.google.accompanist.sample.testharness

import android.os.Bundle
Expand Down
2 changes: 1 addition & 1 deletion testharness/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package com.google.accompanist.testharness {

public final class TestHarnessKt {
method @androidx.compose.runtime.Composable public static void TestHarness(optional long size, optional boolean darkMode, optional androidx.core.os.LocaleListCompat locales, optional androidx.compose.ui.unit.LayoutDirection? layoutDirection, optional float fontScale, optional Integer? fontWeightAdjustment, optional Boolean? isScreenRound, kotlin.jvm.functions.Function0<kotlin.Unit> content);
method @Deprecated @androidx.compose.runtime.Composable public static void TestHarness(optional long size, optional boolean darkMode, optional androidx.core.os.LocaleListCompat locales, optional androidx.compose.ui.unit.LayoutDirection? layoutDirection, optional float fontScale, optional Integer? fontWeightAdjustment, optional Boolean? isScreenRound, kotlin.jvm.functions.Function0<kotlin.Unit> content);
}

}
Expand Down
1 change: 1 addition & 0 deletions testharness/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ dependencies {
implementation(libs.androidx.core)
testImplementation(libs.androidx.core)
implementation(libs.kotlin.coroutines.android)
implementation(libs.compose.ui.test)

// ======================
// Test dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ import kotlin.math.floor
* the [isScreenRound] will be left unchanged.
*/
@Composable
@Deprecated(
replaceWith = ReplaceWith(
"DeviceConfigurationOverride(DeviceConfigurationOverride.ForcedSize(size) " +
"then DeviceConfigurationOverride.DarkMode(darkMode) " +
"then DeviceConfigurationOverride.Locales(LocaleList(locales.toLanguageTags()))" +
"then DeviceConfigurationOverride.LayoutDirection(layoutDirection)" +
"then DeviceConfigurationOverride.FontScale(fontScale)" +
"then DeviceConfigurationOverride.FontWeightAdjustment(fontWeightAdjustment)" +
"then DeviceConfigurationOverride.RoundScreen(isScreenRound), " +
"content)",
"androidx.compose.ui.test.DeviceConfigurationOverride",
"androidx.compose.ui.test.ForcedSize",
"androidx.compose.ui.test.DarkMode",
"androidx.compose.ui.test.Locales",
"androidx.compose.ui.test.LayoutDirection",
"androidx.compose.ui.test.FontScale",
"androidx.compose.ui.test.FontWeightAdjustment",
"androidx.compose.ui.test.RoundScreen",
"androidx.compose.ui.test.then",
"androidx.compose.ui.text.intl.LocaleList",
),
message = "TestHarness has been superceded by DeviceConfigurationOverride in ui-test. " +
"Each argument in TestHarness have been replaced with an individual " +
"DeviceConfigurationOverride, so the suggested replacement is likely unnecessarily " +
"adding overrides for anything that was previously using the default arguments."
)
public fun TestHarness(
size: DpSize = DpSize.Unspecified,
darkMode: Boolean = isSystemInDarkTheme(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")

package com.google.accompanist.testharness

import android.content.res.Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")

package com.google.accompanist.testharness

import androidx.compose.ui.platform.LocalConfiguration
Expand Down

0 comments on commit 0d0198d

Please sign in to comment.