简体   繁体   English

Visual Studio 中的单元测试 Typescript

[英]Unit testing Typescript in Visual Studio

I have been searching for a way to test Typescript in Visual Studio for 2 days now.我一直在寻找一种在 Visual Studio 中测试 Typescript 的方法 2 天了。 It seems that there is an issue in doing this.这样做似乎有问题。 I have tried using different frameworks i just cannot get this to work in a separate project.我曾尝试使用不同的框架,但无法在单独的项目中使用它。 Does anyone have any suggestions on how to get this to work in a separate project?有没有人对如何让它在单独的项目中工作有任何建议? Do I need to create a web interface where this can be run?我是否需要创建一个可以运行它的 Web 界面?

Thank you.谢谢你。

Most TypeScript unit testing frameworks run on the command line.大多数 TypeScript 单元测试框架都在命令行上运行。

To integrate these with Visual Studio, you can use a Task Runner like Gulp.要将这些与 Visual Studio 集成,您可以使用像 Gulp 这样的 Task Runner。

Once you have your gulpfile.js set up to run the tests, it will be visible in the Visual Studio "Task Runner Explorer" window CTRL + ALT + Backspace .设置gulpfile.js以运行测试后,它将在 Visual Studio 的“Task Runner Explorer”窗口中可见CTRL + ALT + Backspace

You can set a task to run whenever you build your solution by right-clicking it in Task Runner Explorer and selecting "Bindings -> After Build".您可以通过在 Task Runner Explorer 中右键单击它并选择“绑定 -> 构建后”,将任务设置为在构建解决方案时运行。

Example Gulp file for Karma: Karma 的 Gulp 文件示例:

/// <binding AfterBuild='test' />
var gulp = require('gulp');
var Server = require('karma').Server;

gulp.task('test', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, done).start();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM