11

I'm a big fan of continuous testing products like Infinitest. Lately I've been doing more JavaScript development, and was looking for something similar for Visua Studio that will run my Jasmine tests immediately after saving a file. Mighty Moose looks like it's just for .NET code. I do like the idea behind Karma, but ideally it would integrate well with Visual Studio 2012.

Is there such a beast?

sjngm
  • 12,423
  • 14
  • 84
  • 114
roufamatic
  • 18,187
  • 7
  • 57
  • 86
  • The most "up to date" VisualStudio extension seems to be from 2015 and can be found here: https://github.com/MortenHoustonLudvigsen/KarmaTestAdapter – Stefan Jul 24 '17 at 12:22
  • The existing extensions did not work well for me. Therefor I decided to use a combination of Gulp tasks, external commands and customized context menus of the solution explorer. The combination of Gulp and Karma is very poweerfull. It allows for example to implement custom watch modes or only test the files that have local changes. – Stefan Jul 31 '17 at 09:41
  • Here is a related open issue for Karma support by Resharper: https://youtrack.jetbrains.com/issue/RSRP-386732 – Stefan Jul 31 '17 at 09:48

4 Answers4

12

I've created a Visual Studio extension you might find useful if you want to use Karma. You basically use Karma as normal, but with an XML reporter enabled; and then a VS extension that watches that XML file and displays the results in the Test Explorer window.

There's a video of it in action (along with text instructions) on my blog: http://blog.dantup.com/2014/03/cross-browser-javascript-testing-with-karma-and-visual-studio/

Feedback welcome!

Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275
  • Sigh. Still relies on "Run Test After Build" which again is a VS Ultimate/Premium feature that's not available in Professional. – roufamatic Oct 24 '14 at 05:59
  • @roufamatic Yes, that's an MS limitation i IBT know a way around :( – Danny Tuppeny Oct 24 '14 at 06:51
  • Is there a VisualStudio extension for Karma that works with VisualStudio Community 2015? Or should I use Chutzpah? (Karma in general seems to be more up to date and has more developers than Chutzpah.) – Stefan Nov 20 '15 at 15:50
  • @Stefan Possibly you could rename the vsix to .zip and edit the manifest file, then rename it back. I haven't tried, and I'm not actively maintaining the extension right now, so 2015 won't be listed in the manifest. – Danny Tuppeny Nov 20 '15 at 16:58
  • 1
    That seems to work. Thank you. I changed the target entry to and the installation ran through. Is it possible to start Karma from within the Visual Studio (e.g. from the Test Explorer) or do I have to use the console? – Stefan Nov 20 '15 at 18:26
  • @Stefan Currently you need to use the console. I did hope to make the extension do more for you, but sadly I just haven't had time. – Danny Tuppeny Nov 21 '15 at 09:01
  • will there be a VS2015 update. – nagates Oct 05 '16 at 20:50
  • 1
    @nagates See the comments above - you can unzip/modify/rezip the vsix to install on 2015. I'm afraid I'm not currently maintaining the extension now though. – Danny Tuppeny Oct 06 '16 at 17:57
2

There's a VS extension for Karma runner integration (shows Karma result in VS Output window): http://visualstudiogallery.msdn.microsoft.com/02f47876-0e7a-4f6c-93f8-1af5d5189225

Buthrakaur
  • 1,821
  • 3
  • 23
  • 35
  • And now one that integrates with the Test Explorer window too! :) http://blog.dantup.com/2014/03/cross-browser-javascript-testing-with-karma-and-visual-studio/ – Danny Tuppeny Mar 09 '14 at 11:21
1

if you want to run javascript unit tests automatically after saving a test file in Visual Studio, you can use "Chutzpah".

http://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe

ps. this is great for JS testing. but if you want to test DOM manipulations you will need some kind of web driver.

edit:

if you set the test explorer to run on build, saving the test.js file will cause the tests to run. saving the referenced javascript itself will not.

user1852503
  • 4,747
  • 2
  • 20
  • 28
  • How do I configure chutzpah to run tests automatically? I see the tests in the test explorer but still have to click on them to do something. – roufamatic Oct 03 '13 at 18:23
  • 2
    @roufamatic At the top left of the Test Explorer panel, just beneath the title, "Test Explorer" you will see a button with an icon which appears to be a combination of a Refresh and Play/Execute. If you mouse over it it will say ... "Run Tests After Build". When this button is active, tests will be run every time the file is saved. – Gary O. Stenstrom Nov 01 '13 at 18:16
  • That button is only available for VS 2012 Ultimate! It's not in the Professional edition. GRRRRRRRRR. – roufamatic Jan 22 '14 at 21:46
  • Well, I have the button on the Premium edition, if that is of any use to you. It's a bit cheaper than ultimate :) – VeteranCoder Feb 06 '14 at 17:06
  • 2
    I'll tell my boss but I don't think he'll go for it, the cheapskate. #selfemployed – roufamatic Mar 10 '14 at 20:47
  • Hey, #selfemployed... aren't YOU the cheapskate boss?:) – CCPony Mar 25 '14 at 13:24
0

For automated builds you can use the following nuget package, which will run your jasmine tests using karma and grunt. So as long as you have nodejs installed on your build machine it should run your unit tests.

https://www.nuget.org/packages/KarmaGruntJSUnit.MSBuild/

Thanks

Manish Kumar
  • 113
  • 3
  • If you prefer to use Gulp instead of Grunt, here are some examples: https://stackoverflow.com/questions/26552729/karma-run-single-test/45350941#45350941 – Stefan Jul 31 '17 at 09:50