What is the proper way of testing custom tasks classes?
When I try to instantiate and object with ‘new’ operator I receive the following exception:
Task of type 'foo.bar.SampleTask' has been instantiated directly which is not supported. Tasks can only be created using the DSL.
It seems to be ok. Then I create the task in the following way:
given:
def project = ProjectBuilder.builder().build()
project.task(SampleTask.NAME, type: SampleTask)
and:
def vst = project.tasks[SampleTask.NAME] as SampleTask
It works, but I can’t set the value of ‘vst’ private field with the following piece of code:
def confs = new TreeMap<Integer,Configuration>()
vst.configurations = confs
The field declaration is as following:
@Inject
private Map<Integere, Configuration> configurations
Don’t bother with ‘@Inject’, it’s not being used while testing but works in production.