Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Getting Started with Unit Testing Part 1

28 minutes, 3 seconds


Right click “Save as…”

This is another in Robert's Getting Started series, where he provides an introduction to a topic that everyone knows about but not everyone is actually doing (or doing enough of). In this episode, part 1 of 3, Robert shows how to get started with unit testing in Visual Studio. The primary goal of unit testing is to take the smallest piece of testable code in an application, isolate it from the remainder of the code, and determine whether it behaves exactly as you expect. Each unit can be tested separately and can easily be tested over and over again.

You can find the sample code and demo scripts for the entire 3 part series here.


Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
  • Good job.  Do you plan to cover how to do data driven testing with MSTest?  It appeared to be a little limited in this area, so I went with NUnit.  Thx.

  • SonalSonal

    This is interesting. I always wanted to learn about testing. How to test JavaScript programs? I create windows 8 apps with JavaScript. In visual studio 2013, I find Test under C# language, but not under JavaScript. How do I get that?

  • @shaggygi: I cover a bit on data driven testing in VS in part 2, which will go live next week. After you see that, let's chat about what you see as the limitations.


  • @Sonal: The Microsoft unit test framework works with managed code. For JavaScript unit testing, you should check out one of the available frameworks. There is a good list of them at http://stackoverflow.com/questions/300855/javascript-unit-test-tools-for-tdd.


  • Personally when I'm trying to learn something new I prefer the smaller chunks at a time.  In fact it seems like PluralSight does that with their videos as well.

  • Proton2Proton2 No Global Warming for 18 Y 9 M ​wattsupwith​that.com

    I don't know what you will be covering in future episodes, but here are some of my notes:


    If your doing Windows Store app development, your going to have to make some changes or additions, for example:

    #if NETFX_CORE
    using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
            [TestCategory( "Timer" ), TestCategory( "Exception expected" )]
    #if !NETFX_CORE
            public void SingleTimer_OnceRanAndStopped_ItShouldNotStartAgain()
                //ToDo: Change exception type to something more appropriate.
                SingleTimer timer = new SingleTimer();
    #if !NETFX_CORE
    #if NETFX_CORE
                Assert.ThrowsException<NotSupportedException>(() => timer.Start());


    Use templated Asserts. Example:

      Assert.AreEqual<int>( 0, timers.Count );

    I have more, but that's enough for now.


  • Deactivated UserDeactivated User

    The manuscript dead tree must be replaced by something geekier like Lumia OneNote RT.

  • @VSChawathe: I am addicted to paper. What can I say? :)

  • Luigi ZambettiLuigi Zambetti

    In the top right side of your Visual Studio environment Robert, you have 2 MB values, maybe is the Ram consumption of Visual Studio itself.
    Is this an extension?

  • @Luigi Zambetti: It is an internal only extension. Sorry.


  • @Luigi Zambetti: It is an internal only extension. Sorry.


  • Thanks Robert for this awesome video. Hope to see more videos in this series.

  • SonOfSamSonOfSam Ultraman vs Godzilla There is no other way

    My humble opinion will be when going from red to green you don't act instead of doing an invalid assert, please let me know what you think.


  • Love the show!

    I would be interested in others opinions on whether testing is only for purist and textbooks and is not practical in real world applications.

    While "unit testing" seems great in theory, I struggle to see that it adds much value to larger applications. Basically it is lots of work to try and get code coverage and building fakes for very little return. Maybe it is just because as an old developer in my early days, my testing was "did it compile?"

  • Great show. I have some notes which aren't that clear to me:

    1. If I want to test a method that has more than one paths, what's better: writing single unit test method that has all testing scenarios or should I divide it into different test methods one for each test case?

    2. If I have a method that has many codes which can be divided into methods but they are used only in the main method. Now if I want to test this method should I first factor these sub-methods and then test them individually or just test it as one method?

    Thanks in advance :)

  • Great video Robert, looking forward to part 2!

  • Stevewlblakeshaw Yeah, right.

    Great episode. I've been adopting unit testing in my latest projects. There were a few things in this video I wasn't aware of, like the ExpectedException attribute. It's also nice to know you can categorize your tests. Looking forward to the next part!

  • I'm well versed on unit testing, but I was curious. I thought you did a great job covering the basics.

  • Nice episode. Please share episode 2 & 3 too.

  • @Niner615224: Episode 2 is now live. I am recording Episode 3 tomorrow and will post it next week.


  • David GallivanDavid Gallivan

    Excellent show.

    I like the shorter segments. It breaks it out like chapters.

  • Thanks for this video . I love it.

  • I really enjoyed this video and the length was just right - I prefer it broken out into chapters. 

    I will be speaking to my team about unit tests today!

  • great session 

  • a must watch to start :)

    I was looking for such basic video. Thanks Green.

  • DanielDaniel

    there's a serious problem with the subtitles of this video (part1), there's a delay several seconds and it is difficult to follow.
    It would be great if you could fix it, thank!

    Thanks for this video!

  • Doctor WhoDoctor Who Picture is of Tom Baker, who played the Doctor, from 1974 to 1980.

    This is really excellent, Rod, thank you for doing this.

    I'm find with breaking up the videos into smaller chunks.

  • Sam stokesSocalSam_ Windows 10=AWESOME

    Good stuff.  Short is better.  Excellent! Thank you!


  • Deactivated UserDeactivated User

    @rogreen:I saw http://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-Studio-2013-Update-3-RC

  • JesseJesse

    Great video on Unit Testing. I'm doing an Independent Study at my University on different types of Automated testing and this is a perfect starting point. You had mentioned books on Test Driven Development. Do you have any in particular you suggest I could potentially look up for my project?


  • ziazia

    sir please define how to apply unit test in web form asp.net

Remove this comment

Remove this thread


Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.