带有Jest单元测试的SonarQube [英] SonarQube with Jest Unit Tests
问题描述
我一直试图找出如何用我的 Jest单元测试和 .net单元测试填充 SonarQube . /p>
我有一个本地版本的 SQ 6.7 和所有最新版本的Javascript和C#插件.
关于Jest,我有 sonar-jest-reporter
导出test-report.xml
文件,并生成lcov.info
文件.
SonarQube能够读取lcov.info
,并且看到覆盖率%,但是无论我将其设置为include
/exclude
还是测试路径,它都不会显示与源文件关联的测试.
文件结构全部为.js
,而.test.js
与每个模块都位于同一目录中.
向我指出正确方向的任何帮助,或者遇到或克服此问题的其他人,将不胜感激.
好像我已经找到了使其工作的方式.诀窍是让sonar.sources
和sonar.tests
都指向同一目录(因为我们在同一目录中同时包含测试和源代码),然后使用sonar.tests.inclusions
来对扩展名为.test.js
或.spec.js
的测试文件进行模式匹配.
这是一个样本sonar-project.properties
,该样本假定以下内容:
-
src/components/Foo/Foo.jsx
主要组件. -
src/components/Foo/Foo.spec.jsx
测试文件.
# Source
sonar.sources=src
# Where to find tests file, also src
sonar.tests=src
# But we get specific here
# We don't need to exclude it in sonar.sources because it is automatically taken care of
sonar.test.inclusions=src/**/*.spec.js,src/**/*.spec.jsx,src/**/*.test.js,src/**/*.test.jsx
# Now specify path of lcov and testlog
sonar.javascript.lcov.reportPaths=coverage/jest/lcov.info
sonar.testExecutionReportPaths=coverage/jest/testlog.xml
现在您的测试文件也会显示.
此处更多信息 >
I've been trying to find out how to populate SonarQube with both my Jest Unit Tests and the .net Unit Tests.
I have a local version of SQ 6.7 and all the latest versions of the Javascript and C# Plugins.
When it comes to Jest, I have the sonar-jest-reporter
to export a test-report.xml
file, and also have the lcov.info
file being generated.
SonarQube is able to read the lcov.info
and I see a coverage %, but no matter what I set as include
/exclude
, or tests path, it will not show the tests associated with the source file.
The file structure is all .js
and the .test.js
are in the same directory with each module.
Any help with pointing me in the correct direction, or others who have encountered and overcome this issue that would be appreciated.
Looks like I've figured out the way to make it work. The trick is to have both sonar.sources
and sonar.tests
point to same directory (because we have both tests and source in the same directory) then use sonar.tests.inclusions
to pattern match test files with .test.js
or .spec.js
extension.
Here's a sample sonar-project.properties
which assumes the following:
src/components/Foo/Foo.jsx
the main component.src/components/Foo/Foo.spec.jsx
the test file.
# Source
sonar.sources=src
# Where to find tests file, also src
sonar.tests=src
# But we get specific here
# We don't need to exclude it in sonar.sources because it is automatically taken care of
sonar.test.inclusions=src/**/*.spec.js,src/**/*.spec.jsx,src/**/*.test.js,src/**/*.test.jsx
# Now specify path of lcov and testlog
sonar.javascript.lcov.reportPaths=coverage/jest/lcov.info
sonar.testExecutionReportPaths=coverage/jest/testlog.xml
Now your test files will also show up.
这篇关于带有Jest单元测试的SonarQube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!