Is there a rule that can find unclosed static mocks

Hi

We are running with the LTS

  • Community Edition
  • Version 8.9.9 (build 56886)

We had the following problem in our code ( and it poped-up when I added a new unit test) when running tests.

For <full class name here>, static mocking is already registered in the current thread

To create a new mock, the existing static mock registration must be deregistered

And the issue was that the testcase writer forgot to close the static mock.

Is this something you have a rule for in later releases or plan to implement?
Or is it something that, most likely, will not make it into SonarQube java since it is specific to
mockito and static mocks.

If it is the latter do you think it is possible to add our own rules?

br,

//mike

Hello @eraonel,

I am not aware of any such rule at the moment but if you could share a self-contained example, you could start developing a new rule suggestion.

Cheers,

Dorian

I note that Java has a link " Writing custom Java rules 101", which gets a 404.

1 Like

Thanks @David_Karr!

We moved the docs to a new CSM recently & that link must have gotten broken in the shuffle. We’ll get it fixed!

 
Ann

1 Like

Hi @David_Karr

Link fixed, thanks!

1 Like