|
I would like to create a analysis project for test codes, especially the test tools and integration test codes.
It should be separated with the original production code quality analysis. But based on my study & search, sonar concurrently doesn't support analysis on test codes. I found that in the latest 3.1 release, there's only PMD Unit Test rules for test codes. I found it very hard to achieve this goal in current sonar, because I have to add the integration code directory in analysis profile, and try to avoid the duplication in the test directory, I have to remove this folder in analysis profile. (I'm using maven BTW) Is there any better solution for this work around? Is there any planning for sonar to support code analysis for different directories, like generated-code/production-code/test category, so the user can apply different customized rules for different directories? Thanks in advance. |
|
Hello,
See my comment below :
I would like to create a analysis project for test codes, especially the test OK But based on my study & search, sonar concurrently doesn't support analysis Indeed I found it very hard to achieve this goal in current sonar, because I have Not sure to understand why you want to say. Could you elaborate a bit more with a simple java example ? ... In fact what Sonar already partially supports is the activation of rules based on the nature of the source code : unit tests code or production code (cf PMD Unit Tests rule engine). The goal is to extend this support by allowing to select on each rule what's the scope of the rule : unit test code, production code or both.
But to be honest I don't see the value to do this by directory. Kind regards, Freddy
|
|
In my project, I have separate directory for integration test. So the project source directory is like this.
project --src/test/java --src/test/ct --src/main/java I would like to analyze integration test codes in src/test/ct In original my pom.xml is like this in build section in pom.xml <sonar.phase>generate-sources</sonar.phase> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-ct-source</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/test/ct</source> </sources> </configuration> </execution> </executions> </plugin> ... But because the sonar will ignore test directory for analysis, so I would move the integration test codes from test to source for sonar analysis purpose. So the pom is some like this, add 2 profile <profile> <id>default</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-ct-source</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/test/ct</source> </sources> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>sonar-test</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/test/ct</source> </sources> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> If I can customized rules for integration test directory(like method length, and duplication), so in the analysis project, I can get results from both production codes and test codes, and with different rules. What I want is hope sonar can support some way to customize the rules for tests (unit test and integration test). And PMD Unit Tests rule engine is for cases using assertion, but for in some test cases, we can use mock/verify way to do the unit test. |
|
Hello,
Indeed for the the being, you can use only rules from the PMD Unit Tests rule engine to analyse your unit test and integration test source files. Feel free to vote for http://jira.codehaus.org/browse/SONAR-3748 in order to be able to activate any rules on unit test source files.
Kind regards, Freddy What I want is hope sonar can support some way to customize the rules for And PMD Unit Tests rule engine is for cases using assertion, but for in some |
| Powered by Nabble | Edit this page |
