How to configure SonarQube Rule S2699 Tests should include assertions
I’m using Karibu Testing for testing my Vaadin applications which work perfectly. But recently, I encountered a problem when I analyzed my code with n. Karibu Testing’s assertion methods are not recognized by SonarQube.
The image below shows the problem:
As you can see, there is an _assert() method call, but SonarQube does not know about Karibu Testing.
By default, SonarQube knows these testing frameworks:
- Eclipse Vert.x
- Fest 1.x and 2.x
- Rest-assured 2.x, 3.x and 4.x
- RxJava 1.x and 2.x
- Truth Framework
But how can we configure SonarQube to recognize Karibu Testing?
The first thing to do is to create a custom Quality Profile. The easiest way is to copy one of the predefined profiles:
Then we need to configure rule S2699. Simply search for it in the rules view:
Then scroll down to Quality Profiles and hit “Change”:
There we have to configure the fully qualified method name. We can use wildcards to add all assert methods using com.github.mvysny.kaributesting.v10.LocatorJ#_assert*
After creating the Quality Profile we have to activate it on our project:
That’s it! When we analyze our project the next time the error is gone.