Set project properties from a plugin implemented in Java

I’m working with a plugin implemented in Java. I’ve added a custom task with reads a project property. I would like to set the project property in the test and validate its functionality. I get a MissingPropertyException when I try this. I guess because setProperty only looks up the property and sets it. How can I create and set project property in a test?

project = ProjectBuilder.builder().build();
.
.
CustomTasks ctask = project.getTasks().create(..., ..);
ctask.getProject().setProperty("prop1", "val1");

Thanks