我有一个带有一些测试的Angular项目.我的版本是用Gulp编写的.我使用Karma运行测试并生成lcov报告.
然后我使用gulp-sonar插件来运行Sonar.我的声纳配置看起来像这样:
"sonar": {
"host": {
"url": "http://mysonar.example.com.au"
},
"projectKey": "sonar:advertising-test",
"projectName": "advertising-test",
"projectVersion": "1.0.0",
"sources": "app/js",
"javascript": {
"lcov": {
"reportPath": "reports/coverage/lcov.info"
}
},
"exec": {
"maxBuffer": "1048576"
}
}
Run Code Online (Sandbox Code Playgroud)
Sonar运行并分析代码,但在尝试使用以下内容读取lcov报告时失败:
[09:38:58] 09:38:58.322 WARN - Problem during processing LCOV report: can't save DA data for line 0.
java.lang.IllegalArgumentException: Line with number 0 doesn't belong to file app/js/main.js
...
[09:38:58] 09:38:58.324 WARN - Problem during processing LCOV report: can't save DA data for line 65.
java.lang.IllegalArgumentException: Line with number 65 …Run Code Online (Sandbox Code Playgroud) 我是Angular的单元测试的新手.我得到了karma代码覆盖率的设置angular-cli.我运行了命令ng-test并打开了代码覆盖率报告.我看到了1x,3x等一起在覆盖报告我的代码行数.请找到我的报道图像.
这是我的测试用例代码 app.component.spec.ts
/* tslint:disable:no-unused-variable */
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
});
});
it('should create the app', async(() => {
let fixture = TestBed.createComponent(AppComponent);
let app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app works!'`, async(() => {
let fixture = TestBed.createComponent(AppComponent);
let app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!');
}));
it('should render …Run Code Online (Sandbox Code Playgroud) 我收到了这份覆盖摘要
=============================== Coverage summary ===============================
Statements : Unknown% ( 0/0 )
Branches : Unknown% ( 0/0 )
Functions : Unknown% ( 0/0 )
Lines : Unknown% ( 0/0 )
================================================================================
Run Code Online (Sandbox Code Playgroud)
我应用了 Angular 文档中指示的更改代码覆盖率:https : //angular.io/guide/testing#enable-code-coverage-report
但我总是得到同样空虚的夏天。
我的 karma.conf.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/singleWindow'),
reports: ['html', 'lcovonly', …Run Code Online (Sandbox Code Playgroud) karma-runner karma-jasmine karma-coverage angular angular-test
我试图在karma框架中使用伊斯坦布尔在karma框架中获取我的打字机代码的代码覆盖率karma.conf中包含了打包的文件,并且通过karma typescript-preprocessor我们能够对打字稿代码进行单元测试和代码覆盖,但代码覆盖率报告来自转换JavaScript代码
如何获取打字稿代码的覆盖率报告?
这是我的karma.conf档案.
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['jasmine'],
preprocessors: {
'src/**/*.ts': ['typescript', 'coverage'],
'test/**/*.ts': ['typescript']
},
typescriptPreprocessor: {
options: {
sourceMap: false, // (optional) Generates corresponding .map file.
target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
module: 'amd', // (optional) Specify module code generation: 'commonjs' or 'amd'
noImplicitAny: true, // (optional) Warn on …Run Code Online (Sandbox Code Playgroud)我一直在试图运行业力报道几天,但现在只找到一个空的空白页面如下.

这是我的配置:
var path = require('path');
var webpackConfig = require('./webpack.common');
module.exports = function (config) {
var _config = {
basePath: '',
frameworks: ['jasmine'],
files: [
{ pattern: './karma-shim.js', watched: false }
],
exclude: [],
preprocessors: {
'./karma-shim.js': ['webpack', 'sourcemap', 'coverage']
},
client: {
captureConsole: false
},
webpack: webpackConfig,
webpackMiddleware: {
stats: 'errors-only'
},
coverageReporter: {
dir: 'coverage/',
reporters: [{
type: 'json',
dir: 'coverage',
subdir: 'json',
file: 'coverage-final.json'
}]
},
remapIstanbulReporter: {
src: 'coverage/json/coverage-final.json',
reports: {
lcovonly: 'coverage/json/lcov.info',
html: 'coverage/html',
'text': …Run Code Online (Sandbox Code Playgroud) 我正在研究角度 6
我在下面的代码中没有任何 else 语句。但是由于没有采用 else 路径,我无法覆盖分支。在这种情况下,我需要做什么才能获得 100% 的分支覆盖率?
getHeaderDocumentList(documents: any) {
if (documents) {
documents.result.docAttachment.forEach(element => {
this.headerdocumentdetails.push(element.DocumentUniqueID);
});
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Jasmine创建我的单元测试,我对所涉及的分支有疑问.
有谁知道为什么代码部分显示分支未被覆盖,我们可以在下面看到?
这是单元测试:
describe('MyComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
let myService: MyService;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyComponent ],
imports: [ MaterializeModule, FormsModule, ReactiveFormsModule, HttpModule ],
providers: [
MyService,
FormBuilder
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyComponent);
component = fixture.componentInstance;
slotsService = TestBed.get(MyService);
fixture.detectChanges();
});
function updateForm(name, surname) {
component.myForm.controls['name'].setValue(name);
component.myForm.controls['surname'].setValue(name);
}
it('should create', () => {
expect(component).toBeTruthy();
});
}
Run Code Online (Sandbox Code Playgroud) 我们在管道中有两种不同类型的测试:单元(.net 核心)和前端(角度/业力)。他们每个人都可以通过“PublishCodeCoverageResults@1”发布代码覆盖率报告,但只有一个正面或背面。这取决于最后运行的测试。我认为最后的报道 owerwrites 以前。但是我们需要同时发布代码覆盖率。
有没有办法合并 2 个覆盖率报告,然后在一个代码覆盖率选项卡中发布它们或添加第二个选项卡?
unit-testing code-coverage karma-coverage azure-devops azure-pipelines
如何使用angular2 + webpack设置karma-coverage?
我从棱角分明的快速启动webpack指南.但覆盖工具是空白的,不显示我的测试.谢谢!
我的文件夹结构是
project
|--src (project files)
|--tests (all my testfiles)
Run Code Online (Sandbox Code Playgroud)
我的webpack.test.js看起来像这样
var helpers = require('./helpers');
module.exports = {
devtool: 'inline-source-map',
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: [
{
test: /\.ts$/,
loaders: ['ts']
},
{
test: /\.html$/,
loader: 'null'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'null'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: 'null'
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'null'
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我的Karma.conf.js
var webpackConfig = require('./webpack.test');
module.exports = …Run Code Online (Sandbox Code Playgroud) 我正在使用 karma-typescript 进行单元测试,并且在期望失败时遇到以下警告:
04 02 2019 15:36:12.927:WARN [reporter]: SourceMap position not found for trace: AssertionError: expected false to be true
at Object.<anonymous> (base/test/api-client.spec.js?f27f5c9809f69dd36e15c3b125fadb70e6a6487a:61:56)
at step (base/test/api-client.spec.js?f27f5c9809f69dd36e15c3b125fadb70e6a6487a:32:23)
at Object.next (base/test/api-client.spec.js?f27f5c9809f69dd36e15c3b125fadb70e6a6487a:13:53)
at fulfilled (base/test/api-client.spec.js?f27f5c9809f69dd36e15c3b125fadb70e6a6487a:4:58)
HeadlessChrome 71.0.3578 (Mac OS X 10.13.6) When determining an endpoint for service should return the resolved endpoint FAILED
AssertionError: expected false to be true
at Object.<anonymous> (test/api-client.spec.ts:23:33 <- test/api-client.spec.js:61:56)
at step (test/api-client.spec.js:32:23)
at Object.next (test/api-client.spec.js:13:53)
at fulfilled (test/api-client.spec.js:4:58)
HeadlessChrome 71.0.3578 (Mac OS X 10.13.6): Executed 1 of 1 …Run Code Online (Sandbox Code Playgroud) karma-coverage ×10
angular ×6
unit-testing ×6
typescript ×5
istanbul ×3
karma-runner ×3
jasmine ×2
angular-test ×1
azure-devops ×1
browserify ×1
javascript ×1
lcov ×1
sonarqube ×1
webpack ×1