Unit testing Typescript in Visual Studio

后端 未结 1 887
刺人心
刺人心 2021-01-19 05:19

I have been searching for a way to test Typescript in Visual Studio for 2 days now. It seems that there is an issue in doing this. I have tried using different frameworks i

1条回答
  •  旧巷少年郎
    2021-01-19 05:44

    Most TypeScript unit testing frameworks run on the command line.

    To integrate these with Visual Studio, you can use a Task Runner like Gulp.

    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.

    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".

    Example Gulp file for Karma:

    /// 
    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();
    });
    

    0 讨论(0)
提交回复
热议问题