How to hesitate multiple class instance creation on a groovy test


Currently i am trying to write a groovy test to test some tasks in my plugin and my plugin have a dependency to another plugin which is reading some configuration. So in plugin apply first i invoke the configs first from the config plugin and then provide that information as input to the tasks which i am working on right now. And my test scenario is like following;

config plugin applied in the root project;

buildscript {
dependencies {
classpath “${mrsProductPluginVersion}”

apply plugin: ‘com.daimler.mrs.config-plugin’

and the other plugin applied in project build.gradle

plugins {
id ‘com.daimler.mrs.liquibase-plugin’

And my plugin invoking the following code to read the configuration from config plugin


This line is not working when i am on a groovy test and we notice that when we apply these plugins from root project and sub project 2 instances of MRSConfigExtension.class and its return null when we call findByType method.

Is there any way to handle this case to hesitate creating multiple instance of a class during tests.

Best Regards.