I need help to develop an unit test layer to assert that my rules are working correctly. However, there is no template test layer for new language rules (like Foo), I tried creating one manually, but I don’t seem to find a way to run this program without fully packaging and installing it within a SonarQube instance.
Problem
I don’t seem to find a way to instantiate a class that implements SensorContext (org\sonar\api\batch\sensor\SensorContext.class) to use in my test layer
If possible, I’d like to see an template Unit Test using the Foo Language in this Example Plugin
I’ve been searching around and found that sonar-java has an implementation regarding testing, is it possible to replicate this behaviour in my plugin?
It’s not completely clear to me. Do you want to implement custom rules for Java language or do you want to implement a completely new plugin to analyze a new language?
If you want to write custom Java rules then you indeed need to use this guide.
However, if you want to implement a completely new language plugin then you will need to use this dependency.
I believe the dependency you sent would not satisfy my needs.
My objective:
On a Higher level: I want to use the example plugin as basis to integrate a non-supported Language and develop new rules.
On a Lower level: I will use a Gherkin parser to analyse Karate DSL code in .feature files. Issues found will be reported and shown in SonarQube.
My plan
I want to fork this Example Plugin into a customized plugin where I can write my implementation.
Problem
I can’t find a way to test this same plugin, there is no way to instantiate SensorContext to extract data from the file.
Is there any way to test rule implementation in this specific plugin, or should I explore another way? TDD is a priority for me.
@balbi_andre since now this is a bit more clear what you’re trying to achieve. So the dependency I shared with you is more to write unit tests and check the rules without the context. So You will need to create your verifier and create a mocked test context.