【发布时间】:2016-07-01 19:24:53
【问题描述】:
我正在使用 Jasmine 从 Grunt 任务中执行测试。我想以 JSON 格式输出测试用例的结果。下面是茉莉花的配置。此配置在 junit 文件夹下生成 XML 文件。
var conf = {
src: [
// '../../../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
options: {
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfig: {
baseUrl: 'SinglePageApplications/' + name,
//waitSeconds: 30,
paths: mixIn({
'knockout-editables': '../../Assets/scripts/vendor/ko.editables-0.9.0',
'knockout-validation': '../../Assets/scripts/vendor/knockout.validation-1.0.2',
'bignumber': '../../Assets/scripts/vendor/bignumber-1.4.1',
'testutils': '../../../Test.UnitTest.JS/Utils',
'shared': '../../Legacy/Shared',
'testdata': '../../../Test.UnitTest.JS/UnitTests/' + name + '/testdata'
}, addConfigurationPaths(app))
}
},
helpers: [
'Assets/scripts/ato/helperscript.js'
],
specs: [
'../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
junit: {
path: 'build/junit/' + name + '/'
},
timeout: 100000,
vendor: arr
}
,
//specs : 'src/test/js/unit-headless.html',
phantomjs: {
'ignore-ssl-errors': true
}
}
我希望结果以 JSON 格式显示,所以我使用 npm 安装了 jasmine-json-test-reporter 并尝试在我当前的配置中实现它,如下所示:
var conf = {
src: [
// '../../../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
options: {
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfig: {
baseUrl: 'SinglePageApplications/' + name,
//waitSeconds: 30,
paths: mixIn({
'knockout-editables': '../../Assets/scripts/vendor/ko.editables-0.9.0',
'knockout-validation': '../../Assets/scripts/vendor/knockout.validation-1.0.2',
'bignumber': '../../Assets/scripts/vendor/bignumber-1.4.1',
'testutils': '../../../Test.UnitTest.JS/Utils',
'shared': '../../Legacy/Shared',
'testdata': '../../../Test.UnitTest.JS/UnitTests/' + name + '/testdata'
}, addConfigurationPaths(app))
}
},
helpers: [
'Assets/scripts/ato/helperscript.js'
//'Legacy/Shared/common/constants.js'
],
specs: [
//'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
//'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
'../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
junit: {
path: 'build/junit/' + name + '/'
},
timeout: 100000,
vendor: arr
}
,
//specs : 'src/test/js/unit-headless.html',
phantomjs: {
'ignore-ssl-errors': true
},
onPrepare: function () {
var JSONReporter = require('jasmine-json-test-reporter');
var jasmine = require('jasmine');
return browser.getProcessedConfig().then(function (config) {
browser.params['browsername'] = config.capabilities.browserName.toUpperCase();
browser.params['version'] = config.capabilities.version || 'latest stable';
browser.params['platform'] = config.capabilities.os + '-' + config.capabilities.os_version;
jasmine.getEnv().addReporter(new JSONReporter({
file: 'results/' + browser.params.platform + '-' + browser.params.version + '.' + browser.params.browsername + '.json',
beautify: true,
indentationLevel: 2 // used if beautify === true
}));
});
}
}
此代码未生成任何 json 文件。我不太确定在当前的 jasmine 配置中使用 jasmine-json-test-reporter。
【问题讨论】: