How to add property to test Project


(dinio.dinev) #1

In my test I have

ProjectInternal project project = HelperUtil.createRootProject()

and then I want to add a property to this project same as I add it through gradle.properties file. I tried project.setProperty(“name”, value) but Gradle adds it as extra property. Can I add it some how as project property directly?


(Peter Niederwieser) #2

What’s the problem with using ‘project.setProperty’? If there is some difference compared to adding a property via ‘gradle.properties’ (I can’t tell offhand), it shouldn’t matter in practice.

PS: ‘HelperUtil’ is an internal class (and was renamed at some point). Instead you should use ‘org.gradle.testfixtures.ProjectBuilder’.


(dinio.dinev) #3

In the docs is written: Sets a property of this project. This method searches for a property with the given name in the following locations, and sets the property on the first location where it finds the property.

The project object itself. For example, the rootDir project property. The project’s Convention object. For example, the srcRootName java plugin property. The project’s additional properties. If the property is not found in any of these locations, it is added to the project’s additional properties.

My property is not found so the last action done. The property is added to additional proeprties - extra proeprties.(Or I am in wrong additional proeprties!=extra proeprties)? But I want to check if it comes from just from gradle.properties file.


(Peter Niederwieser) #4

If it comes from the ‘gradle.properties’ file, it will also end up being an extra property.