I have a web application using Angular 1.5 with bower/npm/gulp coded in Typescript to do our build. Our back end is a c# .net WebApi2. Both are built and deployed on TFS2015. My c# nUnit tests are easy to integrate as part of the build process. The Typescript jasmine unit tests however are more difficult to integrate. How do I get my Typescript jasmine unit tests to run as part of the TFS build and if they fail, fail the build? We have them running through a Jasmine Spec runner and also Karma but not integrated.
我有一个使用Angular 1.5的web应用程序,在Typescript中编码了bower / npm / gulp来进行构建。我们的后端是一个c#.net WebApi2。两者都是在TFS2015上构建和部署的。我的c#nUnit测试很容易作为构建过程的一部分进行集成。然而,Typescript茉莉花单元测试更难以整合。如何让我的Typescript jasmine单元测试作为TFS构建的一部分运行,如果它们失败,则构建失败?我们让他们通过Jasmine Spec跑步者和Karma但没有整合。
I have read the many posts on * integrating Javascript unit tests and each avenue took me through an overly complex solution that didn't work. These include Powershell scripts, Chutzpah amoungst others.
我已经阅读了*集成Javascript单元测试的很多帖子,每条途径都带我通过一个过于复杂的解决方案,但是没有用。这些包括Powershell脚本,Chutzpah amoungst其他。
1 个解决方案
#1
7
Rather than try to recreate the Specrunner via Chutzpah on the build server, which I found difficult to configure and get working. The aim was to get karma to output the running tests in the 'trx' test format that TFS recognises and then publish them to the build. Please note I am using PhantomJs to run my tests through Karma but won't cover that here as it is well covered elsewhere.
而不是尝试在构建服务器上通过Chutzpah重新创建Specrunner,我发现很难配置并开始工作。目的是让业力以TFS识别的'trx'测试格式输出运行测试,然后将它们发布到构建中。请注意我使用PhantomJs通过Karma运行我的测试,但不会覆盖这里,因为它在其他地方有很好的覆盖。
1) install the karma-trx-reporter plugin via npm into your web project (or similar plugin)
1)通过npm将karma-trx-reporter插件安装到你的web项目(或类似的插件)中
2) Configure the Karma.config to include the trx reporter
2)配置Karma.config以包含trx报告器
reporters: ['dots', 'trx'],
trxReporter: { outputFile: 'test-results.trx' },
// notify karma of the available plugins
plugins: [
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-trx-reporter',
],
3) Create a Gulp (or grunt) task to run the karma tests if you don't already have one. Run the task locally and check it creates the 'test-results.trx' specified above. (It doesn't matter where the file is created on the build server):
3)创建一个Gulp(或grunt)任务来运行业力测试,如果你还没有。在本地运行任务并检查它是否创建了上面指定的'test-results.trx'。 (在构建服务器上创建文件的位置无关紧要):
gulp.task('test', function () {
return gulp.src(['tests/*.js']).pipe(karma({
configFile: __dirname + '/Testing/karma.config.js',
singleRun: true
}));
});
4) Add a Gulp (or Grunt) TFS build task to run the karma tests created in the previous step and output the trx file.
4)添加Gulp(或Grunt)TFS构建任务以运行在上一步骤中创建的业力测试并输出trx文件。
5) Add a Gulp (or Grunt) TFS build task to Publish the test results and merge them into the build. Note that the "Test Result Files" path is a wild card **/*.trx to find any trx files in the build path (i.e. finds our previously created file). "Merge Test results" is checked to Merge both our Jasmine test run and our c# test run into the same session. "Continue on error" is unticked to ensure any jasmine test failures break the build.
5)添加Gulp(或Grunt)TFS构建任务以发布测试结果并将它们合并到构建中。请注意,“测试结果文件”路径是一个通配符** / * .trx,用于在构建路径中查找任何trx文件(即查找我们以前创建的文件)。检查“合并测试结果”以将我们的Jasmine测试运行和我们的c#测试运行合并到同一会话中。未完成“继续出错”以确保任何茉莉花测试失败都会破坏构建。
You will notice two sets of tests that have been run and included as part of the build!
您将注意到已经运行并包含在构建中的两组测试!
#1
7
Rather than try to recreate the Specrunner via Chutzpah on the build server, which I found difficult to configure and get working. The aim was to get karma to output the running tests in the 'trx' test format that TFS recognises and then publish them to the build. Please note I am using PhantomJs to run my tests through Karma but won't cover that here as it is well covered elsewhere.
而不是尝试在构建服务器上通过Chutzpah重新创建Specrunner,我发现很难配置并开始工作。目的是让业力以TFS识别的'trx'测试格式输出运行测试,然后将它们发布到构建中。请注意我使用PhantomJs通过Karma运行我的测试,但不会覆盖这里,因为它在其他地方有很好的覆盖。
1) install the karma-trx-reporter plugin via npm into your web project (or similar plugin)
1)通过npm将karma-trx-reporter插件安装到你的web项目(或类似的插件)中
2) Configure the Karma.config to include the trx reporter
2)配置Karma.config以包含trx报告器
reporters: ['dots', 'trx'],
trxReporter: { outputFile: 'test-results.trx' },
// notify karma of the available plugins
plugins: [
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-trx-reporter',
],
3) Create a Gulp (or grunt) task to run the karma tests if you don't already have one. Run the task locally and check it creates the 'test-results.trx' specified above. (It doesn't matter where the file is created on the build server):
3)创建一个Gulp(或grunt)任务来运行业力测试,如果你还没有。在本地运行任务并检查它是否创建了上面指定的'test-results.trx'。 (在构建服务器上创建文件的位置无关紧要):
gulp.task('test', function () {
return gulp.src(['tests/*.js']).pipe(karma({
configFile: __dirname + '/Testing/karma.config.js',
singleRun: true
}));
});
4) Add a Gulp (or Grunt) TFS build task to run the karma tests created in the previous step and output the trx file.
4)添加Gulp(或Grunt)TFS构建任务以运行在上一步骤中创建的业力测试并输出trx文件。
5) Add a Gulp (or Grunt) TFS build task to Publish the test results and merge them into the build. Note that the "Test Result Files" path is a wild card **/*.trx to find any trx files in the build path (i.e. finds our previously created file). "Merge Test results" is checked to Merge both our Jasmine test run and our c# test run into the same session. "Continue on error" is unticked to ensure any jasmine test failures break the build.
5)添加Gulp(或Grunt)TFS构建任务以发布测试结果并将它们合并到构建中。请注意,“测试结果文件”路径是一个通配符** / * .trx,用于在构建路径中查找任何trx文件(即查找我们以前创建的文件)。检查“合并测试结果”以将我们的Jasmine测试运行和我们的c#测试运行合并到同一会话中。未完成“继续出错”以确保任何茉莉花测试失败都会破坏构建。
You will notice two sets of tests that have been run and included as part of the build!
您将注意到已经运行并包含在构建中的两组测试!