【发布时间】:2018-09-07 09:54:58
【问题描述】:
上下文
在一个使用 karma 和 jasmine 进行单元测试的 Angular5 项目中,我正在使用 karma-sonarqube-unit-reporter 为我的单元测试生成此报告文件。
<testExecutions version="1">
<file path="src/app/app.component.spec.ts">
<testCase name="app/app.component.spec.ts should create the app" duration="314"/>
<testCase name="app/app.component.spec.ts should have as title 'Projet de test Angular5'" duration="104"/>
<testCase name="src/app/app.component.spec.ts should render title in a h1 tag" duration="114"/>
</file>
<file path="src/app/client-add/client-add.component.spec.ts">
<testCase name="client-add/client-add.component.spec.ts should create" duration="107"/>
</file>
<file path="app/client.service.spec">
<testCase name="app/client.service.spec #getClients should return an Observable<Client[]>" duration="38"/>
</file>
<file path="src/app/message.service">
<testCase name="app/message.service should be created" duration="35"/>
</file>
</testExecutions>
但是当我将它导入 Sonarqube (v6.7)(通过 Jenkins)时,我得到以下信息
INFO: Sensor Generic Test Executions Report
WARN: Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.
INFO: Parsing C:\Users\adminpp\.jenkins\workspace\ELIS JustElis Beta WEB\reports\ut_report.xml
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 4 unknown files, including:
src/app/app.component.spec.ts
src/app/client-add/client-add.component.spec.ts
src/app/client.service.spec
src/app/message.service
INFO: Sensor Generic Test Executions Report (done) | time=110ms
这是我的声纳属性,用于排除和包含源代码和测试代码。
sonar.sourceEncoding=UTF-8
sonar.sources=.
sonar.exclusions=**/node_modules/**
sonar.test.inclusions = **/*.spec.ts
sonar.import_unkown_files=true
sonar.typescript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=reports/ut_report.xml
我检查了一下,我的 *.spec.ts 文件在它们应该在的位置。
问题
为什么 Sonarqube 找不到我的文件?
我是否错过了某个属性或重要步骤?
(这个属性sonar.test.inclusions = **/*.spec.ts重要吗?)
【问题讨论】:
-
你可以尝试添加属性
sonar.tests=.(值设置为当前目录) -
@TiborBlenessy 我添加了这个属性,但我得到了
ERROR: Error during SonarQube Scanner execution ERROR: File .angular-cli.json can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files也许是因为我添加了sonar.tests=.和sonar.sources=.这使得声纳索引文件两次(一个用于测试,一个用于源)? -
@TiborBlenessy 我的错,我删除了这个属性
sonar.test.inclusions=**/*.spec.ts,因为我认为它不再需要了,这就是给我一个错误的原因。现在我有了这两个属性,声纳会找到我的文件。你知道这两者是如何相关的,为什么我需要两者?
标签: javascript angular unit-testing sonarqube karma-jasmine