In that post I started the process of running the tests on the command prompt. There is also a way to start them from Visual Studio itself.
You can do that with the help of a taskrunner named Gulp.
Gulp is a tool you have to install; I’ll do that with the help of NPM.
Run this command in the directory your karma.conf.js file is located:
Npm install -g gulp --save
(I’m not sure why it must be called gulpfile.js or that it is completely mandatory to do so, but when I renamed the file it didn’t work anymore).
Then add the following content to this file:
This task will start a Karma server and then wait for changes in your (test-)code (like specified in the karma.conf.js file.
You will then also see this task in your task runner:
If you don’t have the task runner visible, use [view] [other windows] [task runner explorer] to show it.
Then, when you change the (test-)code the tests get re-executed for direct feedback.
Happy unit testing!
In the install of gulp, I used the -g switch which installs the package globally.
The NPM docs say “If you want to use a package as a command line tool, then install it globally. This way, it works no matter which directory is current. This is the choice you would use if you were installing grunt, for example.”; and grunt is sort of gulp.
But when I wanted to use the (globally installed) gulp in another project, I did have to install it local to that project too:
Npm install gulp --save