Best way to unit test custom checks?

(Keith Emanuel) #1


I made a custom plugin for analyzing UiPath projects. However, I’m not sure what the best way to implement unit tests for the checks is.

I’m not a SonarQube plugin expert, but it seems lot of the plugin depends on a SensorContext. Is there a way I can create a SensorContext for unit testing?

I’m also setting custom Properties (Using PropertyDefinition, which also depends on the SensorContext) in the settings. Is there a way alter the properties and unit test the checks with the altered values?

Is there any code I can look through that does something similar?

Thanks in advance.

(Julien Henry) #2

Hi Keith,

There is a SensorContextTester utility class provided to ease mocking of Sensor, and asserting. I suggest you have a look, and come back here if you have more specific questions.

To test settings, you can use MapSettings. You can pass your property definitions if you also want to test default values. If you are using the ‘new’ Configuration interface, simply use MapSettings::asConfig.