3

Here's the situation:

  • We're a Microsoft shop using Visual Studio / TFS etc.
  • We have a build server that nightly performs builds for us and runs various tests to ensure nothing has been broken during the day
  • We're now doing more and more JavaScript and this is likely to continue.

None of our JavaScript is currently tested because as I've looked around I've found the JavaScript testing world is in a state of flux. There are lots of offerings which I've read about and I'm not sure which path to take. I found this question quite helpful in terms of just raw info:

JavaScript unit test tools for TDD

Ideally I'd like to use something which integrates nicely into Visual Studio and our TFS build server. Most of the JavaScript testing options do not seem to support this.

I found this article: (but I'm not too keen on using jscript for testing)

http://stephenwalther.com/blog/archive/2010/12/20/integrating-javascript-unit-tests-with-visual-studio.aspx

And I found this - which looks quite promising:

http://chutzpah.codeplex.com/

So what I'm wondering is, is there any consensus yet? Are people adopting one tool over another, is any approach gaining critical mass yet? I'm keen to make use of something which is clearly working for a lot of people already.

Is it worthwhile me sticking it out for a JavaScript testing framework that plays nice with Visual Studio / TFS or should I look to use one of the non Microsoft friendly offerings instead?

All insights appreciated!

Community
  • 1
  • 1
John Reilly
  • 5,791
  • 5
  • 38
  • 63

3 Answers3

3

I wouldn't got that far and state that I'm moving away from developing in MS environment. I think Visual Studio is a great tool. Working a little with Eclipse & XCode, for PhoneGap development even gave me another perspective as to how Visual Studio really rocks.

Regarding JavaScript, there are many enhancements in Visual Studio 2012, but integral solution for Unit Testing is not yet part of it.

After being involved in some JavaScript heavy projects, also felt the need for Unit Testing, so started with In-Browser tests with QUnit and Sinon.JS.

I went out there to find the right stack to meet my expectations:

  • Seamless integration with Visual Studio. So we can run tests without leaving the IDE.

  • Headless testing. Against multiple browsers at the same time if possible.

  • Support for AMD (Asynchronous Module Definition) / Require.JS.

  • Support for Async Tests.

  • Documented libraries & Tools.

  • Free Tools are preferred.

Eventually find my perfect combination for Headless testing from inside the IDE with JS-Test-Driver.

I've written a 3 parts series on my blog:

  • Part I - Expectations & the selected Stack

  • Part II - Setting up the environment for Headless tests

  • Part III - Testing AMD/Require.JS Modules

You can find the last part here, with links to first 2 posts:

http://www.upstruct.net/2013/02/javascript-unit-testing-in-visual-part-3.html

Been using this combination in several projects, and got a very good feedback from the teams so far.

Let me know if it suits you...

  • Thanks for this Yaniv. Have you seen this course on Pluralsight as well? http://pluralsight.com/training/courses/TableOfContents?courseName=testing-javascript&highlight=joe-eames_testing-javascript-m4-mocking*3!joe-eames_testing-javascript-m7-utilities#testing-javascript-m4-mocking – John Reilly Feb 27 '13 at 09:17
  • Great. No, haven't seen it. But following the link you provided I've went over the TOC. Seems great. I've considered both Testacular & Jasmine, but didn't find much documentation for Testacular at the time, and found qUnit & Sinon.JS much more strong than Jasmine. – Yaniv Yechezkel Mar 03 '13 at 05:26
1

I've been looking around for the same answer but am now wondering if I should move away from developing in an MS environment altogether. As more and more of what I do is on the client side, Visual Studio seems less relevant. Funnily enough though, since I've been playing with Eclipse I've had the same problem - lack of JS testing plugins! So I'm not sure there's a consensus outside of MS development. I think part of this is a reluctance of seasoned developers of C# / Java to use JS but rather they want to use a strongly typed language which compiles (using tools like GWT and Script Sharp). The result is confusion about what comprises best practice. But since the tools for JS seem to be improving I'm somewhat reluctantly coming to the conclusion that JS should be the first point for coding rather than adding another layer of abstraction. Thus I'm resigned to using their available tools - QUnit for the moment is my choise.

  • Thanks for the thoughts Matthew. Things don't seem to have got much clearer in the time since I asked the question! I know what you mean about doing more and more on the client side but I'm really liking the tooling in Visual Studio for JS. Particularly the latest and greatest version. Don't know how Eclipse measures up on that front? For now QUnit it is I guess... – John Reilly Aug 26 '12 at 18:36
0

In 2021 it seems that Microsoft is recommending we use a NodeJS app to run our JavaScript Unit Tests. Visual Studio's test window can now see tests we write in that project even when the overall project is in C#:

One of the testing library combos (unit testing / mocking / assertions) recommended is using Mocha / Sinon / Chai. For this flavor there's a useful tutorial located here:

Paulito.Bandito
  • 136
  • 2
  • 6