Karma for Visual Studio? [closed]
Asked Answered
A

4

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?

Absquatulate answered 30/9, 2013 at 23:21 Comment(3)
The most "up to date" VisualStudio extension seems to be from 2015 and can be found here: github.com/MortenHoustonLudvigsen/KarmaTestAdapterMercorr
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.Mercorr
Here is a related open issue for Karma support by Resharper: youtrack.jetbrains.com/issue/RSRP-386732Mercorr
D
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!

Durkheim answered 9/3, 2014 at 11:21 Comment(8)
Sigh. Still relies on "Run Test After Build" which again is a VS Ultimate/Premium feature that's not available in Professional.Absquatulate
@Absquatulate Yes, that's an MS limitation i IBT know a way around :(Durkheim
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.)Mercorr
@Mercorr 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.Durkheim
That seems to work. Thank you. I changed the target entry to <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[14.0]" /> 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?Mercorr
@Mercorr 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.Durkheim
will there be a VS2015 update.Father
@Father 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.Durkheim
R
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

Rahmann answered 3/12, 2013 at 8:18 Comment(1)
And now one that integrates with the Test Explorer window too! :) blog.dantup.com/2014/03/…Durkheim
S
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.

Skeptical answered 3/10, 2013 at 8:47 Comment(6)
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.Absquatulate
@Absquatulate 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.Warchaw
That button is only available for VS 2012 Ultimate! It's not in the Professional edition. GRRRRRRRRR.Absquatulate
Well, I have the button on the Premium edition, if that is of any use to you. It's a bit cheaper than ultimate :)Tadtada
I'll tell my boss but I don't think he'll go for it, the cheapskate. #selfemployedAbsquatulate
Hey, #selfemployed... aren't YOU the cheapskate boss?:)Lanie
L
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

Lulululuabourg answered 16/10, 2014 at 4:59 Comment(1)
If you prefer to use Gulp instead of Grunt, here are some examples: https://mcmap.net/q/118698/-karma-run-single-test/…Mercorr

© 2022 - 2024 — McMap. All rights reserved.