Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bootstage/testkit-gradle-plugin
Testkit for Android gradle plugin testing
https://github.com/bootstage/testkit-gradle-plugin
android gradle testkit
Last synced: 4 days ago
JSON representation
Testkit for Android gradle plugin testing
- Host: GitHub
- URL: https://github.com/bootstage/testkit-gradle-plugin
- Owner: bootstage
- License: apache-2.0
- Created: 2020-10-20T23:42:20.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-03T00:54:36.000Z (over 1 year ago)
- Last Synced: 2024-11-15T09:48:48.845Z (3 months ago)
- Topics: android, gradle, testkit
- Language: Kotlin
- Homepage: https://testkit.bootstage.io
- Size: 872 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Introduction
Android developers might be use Android Gradle plugin's internal API to build custom gradle plugins for Android project, the idea is great, but the internal API of Android Gradle plugin is unstable, in fact, the internal API of each major release of Android Gradle plugin always has significant changes, It takes too much efforts on compatibility testing.
The goal of [testkit-gradle-plugin](https://plugins.gradle.org/plugin/io.bootstage.testkit) is to make the custom Android gradle plugin testing easier and more efficient
## Getting Started
### Create gradle project structure
Create Gradle project structure under Java resources directory
```
src/integrationTest/resources
├── build.gradle
└── src
└── main
└── java
└── main.kt
```#### build.gradle
```gradle
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'io.bootstage.testkit' version '1.3.0'
}repositories {
mavenLocal()
google()
mavenCentral()
jcenter()
}dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.72"
}compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}apply from: "$rootDir/gradle/integration-test.gradle"
```
### gradle/integration-test.gradle
```gradle
sourceSets {
integrationTest {
java {
srcDirs += []
}
kotlin {
srcDirs += ['src/integrationTest/kotlin', 'src/integrationTest/java']
}
resources.srcDir file('src/integrationTest/resources')
compileClasspath += sourceSets.main.output + configurations.testRuntime
runtimeClasspath += output + compileClasspath
}
}configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
}task integrationTest(type: Test) {
description = 'Runs the integration tests.'
group = 'verification'
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
mustRunAfter test
}check.dependsOn integrationTest
compileIntegrationTestKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
}gradlePlugin {
testSourceSets sourceSets.integrationTest
}
```### Write test code
```kotlin
class SimpleIntegrationTest {private val projectDir: TemporaryFolder = TemporaryFolder()
@get:Rule
val chain: RuleChain = rule(projectDir) { projectDir ->
GradleExecutor(projectDir::getRoot)
}@Test
@Case(SimpleTestCase::class)
fun `test gradle build`() {
projectDir.copyFromResource("build.gradle")
projectDir.copyFromResource("src")
}}
class SimpleTestCase : TestCase {
override fun apply(project: Project) {
project.projectDir.walkTopDown().forEach(::println)
}
}
```### Run tests
Running test by executing the following command:
```bash
./gradlew cleanTest integrationTest
```