I have created a <library to help test Gradle plug...
# community-news
i
I have created a library to help test Gradle plugins! It lets you create temporary builds and run them with Gradle TestKit to ensure your tests never impact each other:
Copy code
test("A test that uses Gradle") {
	// Create Kotlin or Grovvy DSL files directly…
	gradle.settingsKts("""
		include("foo")
	""".trimIndent())

	gradle.rootProject.buildKts("""
		tasks.register("test") {
			doLast {
				println("Testing the root project")
			}
		}
	""".trimIndent())

	// …create multi-project builds easily…
	gradle.project("foo").buildKts("""
		tasks.register("test") {
			doLast {
				println("Testing the :foo project")
			}
		}
	""".trimIndent())

	// …start a Gradle instance in the related project…
	val result = gradle.runner()
		.withArguments("test")
		.build()

	// …assert that the output is as expected.
	result.output shouldContain "Testing the root project"
	result.output shouldContain "Testing the :foo project"
}
Each time the test runs, it creates a new clean directory in which all files are created and the build is run. If the test is successful, the directory is deleted. If the test fails, its path is printed and it is kept intact so you can visit it and analyze it further.
r
This seems pretty similar (at least in concept) with the autonomousapps testkit support plugin.
i
It looks similar indeed. My goal was specifically handling the working directory to avoid collisions, everything else in my example is from the official TestKit lib 🙂