# JUnit Test - static quality code scan

**URL:** <https://community.sonarsource.com/t/junit-test-static-quality-code-scan/37183>\
**Category:** SonarQube Server / Community Build\
**Tags:** junit, java\
**Created:** [January 18, 2021, 12:50pm UTC](https://community.sonarsource.com/t/junit-test-static-quality-code-scan/37183 "2021-01-18T12:50:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Riel](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@Riel](https://community.sonarsource.com/u/Riel)\
**Post date:** [January 18, 2021, 12:50pm UTC](https://community.sonarsource.com/t/junit-test-static-quality-code-scan/37183/1 "2021-01-18T12:50:12Z")

</div>

Qonarqube version: 8.6 (build 39681)

Here is what I would like to achieve:  
For a given project, to enable some rules for code source AND for my junit tests. For example, the rule _java:S2208 Wildcard imports should not be used_ should be enabled whatever the type of code (source or tests). Some rules about complexity could be violated by JUnit tests code but not by source code.

Is it already possible to do it?

Workaround (that I’ve not tested):  
I could include the junit tests as normal source code during the code scanning but then the same rules will be enabled for test and source code.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [January 18, 2021, 9:07pm UTC](https://community.sonarsource.com/t/junit-test-static-quality-code-scan/37183/2 "2021-01-18T21:07:01Z")

</div>

Hi,

Welcome to the community!

> [@Riel](#):
>
> I could include the junit tests as normal source code during the code scanning but then the same rules will be enabled for test and source code.

This is indeed the most common approach.

I’d love to tell you there’s a secret switch to turn this on otherwise, but unfortunately there’s not.

&nbsp;  
🤷‍♀️  
Ann

---

<div class="post-metadata">

**Author:** ![Riel](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@Riel](https://community.sonarsource.com/u/Riel)\
**Post date:** [January 22, 2021, 11:01am UTC](https://community.sonarsource.com/t/junit-test-static-quality-code-scan/37183/3 "2021-01-22T11:01:39Z")

</div>

Ok thanks for the info. Could it be a valid features to have in future release?  
Something like be able to flag a rule to be executed on test source code too.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [January 22, 2021, 12:18pm UTC](https://community.sonarsource.com/t/junit-test-static-quality-code-scan/37183/4 "2021-01-22T12:18:08Z")

</div>

Believe me, we’re aware of the need. I’ve lobbied for this literally for years.

&nbsp;  
😶  
Ann

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [January 29, 2021, 12:18pm UTC](https://community.sonarsource.com/t/junit-test-static-quality-code-scan/37183/5 "2021-01-29T12:18:15Z")

</div>

Closed on January 29, 2021, 12:18pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
