Skip to content

Commit

Permalink
Merge pull request #87 from martinbonnin/add-plugin-tests
Browse files Browse the repository at this point in the history
Add a simple plugin test
  • Loading branch information
cortinico committed Feb 4, 2020
2 parents 5ab43f0 + 0f62c91 commit 80e2315
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
18 changes: 18 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ pluginBundle {
}
}

configure<PublishingExtension> {
// Add a local repository for tests.
// The plugin tests will use this repository to retrieve the plugin artifact.
// This allows to test the current code without deploying it to the gradle
// portal or any other repo.
repositories {
maven {
name = "pluginTest"
url = uri("file://${rootProject.buildDir}/localMaven")
}
}
}

detekt {
toolVersion = "1.4.0"
input = files("src/")
Expand All @@ -69,3 +82,8 @@ tasks.jacocoTestReport {
tasks.check {
dependsOn(tasks.jacocoTestReport)
}

tasks.withType<Test> {
dependsOn("publishPluginMavenPublicationToPluginTestRepository")
inputs.dir("src/test/testProject")
}
28 changes: 28 additions & 0 deletions plugin/src/test/java/com/yelp/plugin/PluginTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.yelp.plugin

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Test
import java.io.File


class PluginTests {
@Test
fun basicPluginTest() {
val tmpDir = File(".", "build/testProject")
tmpDir.deleteRecursively()

println(File(".").absolutePath)
File(".", "src/test/testProject").copyRecursively(tmpDir)

val result = GradleRunner.create().withProjectDir(tmpDir)
.forwardStdOutput(System.out.writer())
.forwardStdError(System.err.writer())
.withArguments("generateSwagger")
.build()

Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":generateSwagger")?.outcome)
}
}
30 changes: 30 additions & 0 deletions plugin/src/test/testProject/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import com.yelp.codegen.plugin.GenerateTaskConfiguration

buildscript {
repositories {
maven {
url = uri("../../../build/localMaven")
}
jcenter {
content {
excludeGroup("com.yelp.codegen")
}
}
}
dependencies {
// Always take the latest version from the local test repo
// This is not super robust and we could find a way to communicate the version to the testProject
// by copying the root buildSrc to the testProject or extracting the version in a properties file
classpath("com.yelp.codegen:plugin:+")
}
}

apply(plugin = "com.yelp.codegen.plugin")

configure<GenerateTaskConfiguration> {
platform = "kotlin"
packageName = "com.yelp.codegen.samples"
// this file is in rootDir/plugin/build/testProject/
inputFile = file("../../../samples/junit-tests/junit_tests_specs.json")
outputDir = file("./build/generatedSources")
}
1 change: 1 addition & 0 deletions plugin/src/test/testProject/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name="testProject"

0 comments on commit 80e2315

Please sign in to comment.