Testing Custom Plugin Extension

What’s a good way to write unit tests for gradle custom plugin’s extension to ensure DSL in build.gradle results in appropriate behavior? I can invoke my plugin and check my extension’s type but am unsure how to push configurations into it using a string.

public static void setupOnce() {
  project = ProjectBuilder.builder().build()
  project.apply plugin: 'bambooPlanPlugin'
public void checkExtensionAccess() {
  assertTrue(project.extensions.getByName('bamboobuild') instanceof BambooBuildExtension)

public void parseExtensionConfig() {
  def = "bamboobuild {  projects { foo { var = 'bar' } } }"
 ...  Now I'm usure of this part
 assertEquals( check extension value against expected foo and bar
public void configureExtension() {
  project.extensions.configure(BambooBuildExtension, new ClosureBackedAction<BambooBuildExtension>(
     insert - DSL text here -
BambooBuildExtension ext = project.extensions.getByName('bamboobuild')

Now you can test the object

I would think this is what nebula-test is good for. Once this is fully integrated, it’s almost easier to test plugins with a build script than with raw code.

1 Like