3xGuy
3xGuy

Reputation: 2559

Unit testing Typescript in Visual Studio

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 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?

Thank you.

Upvotes: 4

Views: 1712

Answers (1)

Fenton
Fenton

Reputation: 251012

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:

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

Upvotes: 2

Related Questions