Resolving SonarQube Rule S2699 with Karibu Testing Assertions
![blog-post-img](https://martinelli.ch/wp-content/uploads/2023/06/pexels-pixabay-209954-1.jpg)
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 Problem
The image below shows the problem:
![](https://martinelli.ch/wp-content/uploads/2023/06/image-1024x238.png)
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:
- AssertJ
- Awaitility
- EasyMock
- Eclipse Vert.x
- Fest 1.x and 2.x
- Hamcrest
- JMock
- JMockit
- JUnit
- Mockito
- Rest-assured 2.x, 3.x and 4.x
- RxJava 1.x and 2.x
- Selenide
- Spring’s
org.springframework.test.web.servlet.ResultActions.andExpect()
andorg.springframework.test.web.servlet.ResultActions.andExpectAll()
- Truth Framework
- WireMock
But how can we configure SonarQube to recognize Karibu Testing?
The Solution
The first thing to do is to create a custom Quality Profile. The easiest way is to copy one of the predefined profiles:
![](https://martinelli.ch/wp-content/uploads/2023/06/image-9-1024x608.png)
Then we need to configure rule S2699. Simply search for it in the rules view:
![](https://martinelli.ch/wp-content/uploads/2023/06/image-3-1024x608.png)
Then scroll down to Quality Profiles and hit “Change”:
![](https://martinelli.ch/wp-content/uploads/2023/06/image-4-1024x239.png)
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*
![](https://martinelli.ch/wp-content/uploads/2023/06/image-6-1024x608.png)
After creating the Quality Profile we have to activate it on our project:
![](https://martinelli.ch/wp-content/uploads/2023/06/image-7-1024x608.png)
![](https://martinelli.ch/wp-content/uploads/2023/06/image-8-1024x608.png)
That’s it! When we analyze our project the next time the error is gone.
Related Posts
- Fly.io and Neon: The Perfect Combination to Run Your Java Applications - 16.07.2024
- The Best Way to Handle Phone Numbers - 19.06.2024
- Connect to Google Cloud SQL from Java - 18.06.2024