이 자동화 된 단위 테스트 malarkey를 배우려고합니다. Grunt를 사용하여 자동으로 Mocha 테스트를 실행하고 테스트 결과를 파일로 출력하고 싶습니다. 내가 할 수있는 한, grunt-mocha-cov을 사용해야합니다. 나는 일종의 일을했습니다. 테스트가 그루트를 통과하면 결과 파일을 씁니다. 확인을 누릅니다. 그러나 그들 중 하나가 실패하면 나는 이것을 얻는다 :테스트 실행이 실패 할 때 모카를 실행합니다.
Running "mochacov:all" (mochacov) task
Warning: Use --force to continue.
Aborted due to warnings.
파일이 생성되지 않는다. 아무도 내가 잘못 가고 있다고 말할 수 있습니까?
내 프로젝트의 다음과 같은 구성 :내 테스트 폴더는 다음과 같습니다 하나의 파일, test.js, 포함
:var chai = require("chai"),
assert = chai.assert,
expect = chai.expect;
var foobar = {
sayHello: function() {
return 'Hello World!';
}
}
describe('Foobar', function() {
describe('#sayHello()', function() {
it('should work with assert', function() {
assert.equal(foobar.sayHello(), 'Hello World!');
});
it('should work with expect', function() {
expect(foobar.sayHello()).to.equal('Hello Worlxd!');
});
});
});
package.json이있다을
{
"name": "GruntTest",
"version": "0.0.1",
"private": true,
"devDependencies": {
"grunt": "~0.4.1",
"grunt-mocha-cli": "~1.3.0",
"grunt-contrib-qunit": "~0.3.0",
"grunt-contrib-jshint": "~0.6.4",
"grunt-mocha": "~0.4.1",
"should": "~2.0.1",
"chai": "~1.8.1",
"grunt-mocha-cov": "0.0.7"
},
"description": "Grunt Test",
"main": "grunt.js",
"dependencies": {
"grunt": "~0.4.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD"
}
여기 내 Gruntfile.js가 있습니다.
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
mochacov: {
options: {
reporter: 'XUnit',
require: ['should'],
output: 'test-results.xml',
bail: false
},
all: ['test/*.js']
}
});
grunt.loadNpmTasks('grunt-mocha-cov');
grunt.registerTask('default', ['mochacov']);
};
편집
는 자비의 조언에 따라 나는 mochacov과 xUnit의 파일 기자로 일하고 있어요. 여기에 다른 나의 새로운 개선 Gruntfile, 경우에 유용에 사람의 : 단말기가 경고를 제공
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
mochacov: {
options: {
reporter: 'xunit-file',
require: ['should'],
bail: false
},
all: ['test/*.js']
}
});
grunt.loadNpmTasks('grunt-mocha-cov');
grunt.registerTask('default', ['mochacov']);
};
"이 때문에 경고를 중단되었습니다"하지만 mochacov는 시험 결과와 파일 xunit.xml을 만듭니다.
감사합니다. xavier - grunt-simple-mocha가 콘솔로 출력하는 중입니다. xunit-file이 작동하는 데 문제가 있습니다. 나는 계속 노력할 것이다. –
지난 번 서버 쪽에서 grunt를 사용했을 때 다음과 같았습니다. https://github.com/xseignard/rss-unify/tree/a560641050a3e8e06bb040220e53feff83a1003d/server보세요 –
고맙습니다. Xavier 님, 제가 mochacov와 함께 작업하게되었습니다! –