Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test Harness] Add test harness library #1392

Merged
merged 24 commits into from Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6661981
Test Harness initial commit
JoseAlcerreca Nov 10, 2022
2e7cdae
Add initial test harness implementation
alexvanyo Nov 10, 2022
62a906e
Adds unit tests
JoseAlcerreca Nov 17, 2022
01b04f0
Added Locale and font unit tests
JoseAlcerreca Nov 17, 2022
ad681b3
Improves unit tests, including API23 and robolectric
JoseAlcerreca Nov 18, 2022
80dbe7e
Spotless and cleanup
JoseAlcerreca Nov 18, 2022
6dc5f5c
Metalava regenerated
JoseAlcerreca Nov 18, 2022
a2117d3
Trying to fix inst tests by providing a noop Config annotation
JoseAlcerreca Nov 18, 2022
d2c7087
Add Robolectric + JaCoCo support
alexvanyo Nov 18, 2022
2d151d4
Add test harness issue template
alexvanyo Nov 21, 2022
06fc618
Add initial documentation draft
alexvanyo Nov 21, 2022
c24138e
Use test harness in pager tests
alexvanyo Nov 21, 2022
ffb84cd
Use test harness in adaptive tests
alexvanyo Nov 21, 2022
a8ba4e8
Fix formatting for pager tests
alexvanyo Nov 21, 2022
bef9c21
Adjust size overriding to ensure requested size is available
alexvanyo Nov 21, 2022
28874d6
Increase tolerance for TwoPane tests to 1 pixel
alexvanyo Nov 21, 2022
ccb8496
Fix parameter table in test harness docs
alexvanyo Nov 21, 2022
cb830e2
Remove ratio is at least 1 check
alexvanyo Nov 21, 2022
cfeeb04
Spotless
JoseAlcerreca Nov 22, 2022
9067dc5
Adds test harness sample
JoseAlcerreca Nov 22, 2022
398a371
spotless
JoseAlcerreca Nov 22, 2022
cbdd45e
Adds locale to test harness sample
JoseAlcerreca Nov 22, 2022
40ea604
Add layoutlib limitation to docs
alexvanyo Nov 22, 2022
5adcbc5
Add stringResource test for testharness
alexvanyo Nov 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -67,6 +67,9 @@ A wrapper around WebView for basic WebView support in Jetpack Compose.
### 📜 [Adaptive](./adaptive/)
A library providing a collection of utilities for adaptive layouts.

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

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

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Expand Up @@ -84,7 +84,7 @@ androidx-test-espressoWeb = "androidx.test.espresso:espresso-web:3.5.0-alpha07"

junit = "junit:junit:4.13.2"
truth = "com.google.truth:truth:1.1.2"
robolectric = "org.robolectric:robolectric:4.8"
robolectric = "org.robolectric:robolectric:4.9"

affectedmoduledetector = "com.dropbox.affectedmoduledetector:affectedmoduledetector:0.1.2"

Expand Down
2 changes: 2 additions & 0 deletions sample/build.gradle
Expand Up @@ -61,6 +61,8 @@ dependencies {
implementation project(':flowlayout')
implementation project(':systemuicontroller')
implementation project(':swiperefresh')
testImplementation project(':testharness')
androidTestImplementation project(':testharness')
implementation project(':web')

implementation libs.androidx.appcompat
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Expand Up @@ -43,4 +43,5 @@ include ':flowlayout'
include ':systemuicontroller'
include ':swiperefresh'
include ':sample'
include ':testharness'
include ':web'
21 changes: 21 additions & 0 deletions testharness/README.md
@@ -0,0 +1,21 @@
# Test Harness for Jetpack Compose

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

For more information, visit the documentation: https://google.github.io/accompanist/testharness

## Download

```groovy
repositories {
mavenCentral()
}

dependencies {
implementation "com.google.accompanist:accompanist-testharness:<version>"
}
```

Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. These are updated on every commit.

[snap]: https://oss.sonatype.org/content/repositories/snapshots/com/google/accompanist/accompanist-testharness/
9 changes: 9 additions & 0 deletions testharness/api/current.api
@@ -0,0 +1,9 @@
// Signature format: 4.0
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, kotlin.jvm.functions.Function0<kotlin.Unit> content);
}

}

140 changes: 140 additions & 0 deletions testharness/build.gradle
@@ -0,0 +1,140 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id 'com.android.library'
id 'kotlin-android'
id 'org.jetbrains.dokka'
}

kotlin {
explicitApi()
}

android {
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
// targetSdkVersion has no effect for libraries. This is only used for the test APK
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
debug {
enableUnitTestCoverage = true
}
}

buildFeatures {
buildConfig false
compose true
}

composeOptions {
kotlinCompilerExtensionVersion libs.versions.composeCompiler.get()
}

lintOptions {
textReport true
textOutput 'stdout'
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks
checkReleaseBuilds false
}

packagingOptions {
// Some of the META-INF files conflict with coroutines-test. Exclude them to enable
// our test APK to build (has no effect on our AARs)
excludes += "/META-INF/AL2.0"
excludes += "/META-INF/LGPL2.1"
}

testCoverage {
jacocoVersion = "0.8.8"
}

testOptions {
unitTests {
includeAndroidResources = true
}
unitTests.all {
useJUnit {
excludeCategories 'com.google.accompanist.internal.test.IgnoreOnRobolectric'
}
jacoco {
// Required for JaCoCo + Robolectric
// https://github.com/robolectric/robolectric/issues/2230
includeNoLocationClasses = true

// Required for JDK 11 with the above
// https://github.com/gradle/gradle/issues/5184#issuecomment-391982009
excludes = ["jdk.internal.*"]
}
}
animationsDisabled true
}

sourceSets {
test {
java.srcDirs += 'src/sharedTest/kotlin'
res.srcDirs += 'src/sharedTest/res'
}
androidTest {
java.srcDirs += 'src/sharedTest/kotlin'
res.srcDirs += 'src/sharedTest/res'
}
}
}

dependencies {
implementation libs.compose.foundation.foundation
implementation libs.androidx.core
testImplementation libs.androidx.core
implementation libs.napier
implementation libs.kotlin.coroutines.android

// ======================
// Test dependencies
// ======================

androidTestImplementation project(':internal-testutils')
testImplementation project(':internal-testutils')

androidTestImplementation libs.junit
testImplementation libs.junit

androidTestImplementation libs.truth
testImplementation libs.truth

androidTestImplementation libs.compose.ui.test.junit4
testImplementation libs.compose.ui.test.junit4

androidTestImplementation libs.compose.ui.test.manifest
testImplementation libs.compose.ui.test.manifest

androidTestImplementation libs.androidx.test.runner
testImplementation libs.androidx.test.runner

testImplementation libs.robolectric
}

apply plugin: "com.vanniktech.maven.publish"
3 changes: 3 additions & 0 deletions testharness/gradle.properties
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=accompanist-testharness
POM_NAME=Accompanist Test Harness
POM_PACKAGING=aar
@@ -0,0 +1,20 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.robolectric.annotation

// No-op annotation for instrumented tests to build
annotation class Config(val sdk: IntArray)
18 changes: 18 additions & 0 deletions testharness/src/main/AndroidManifest.xml
@@ -0,0 +1,18 @@
<!--
~ Copyright 2021 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<manifest package="com.google.accompanist.testharness">
</manifest>