How to Re-Enable Create Unit Tests Context Menu In Visual Studio 2012

To re-enable the Create Unit Tests… menu, go to Tools->Customize… to launch the Customize dialog. At the Customize dialog, go to the Commands tab, select the Context menu radio button and choose Editor Context Menus | Code Window.

You will realized that the menu item is actually available in the context menu. 🙂 The VS developers were kind enough to leave it there for us. *HeHe* Click on the Create Unit Tests… menu item and click either Move Up or Move Down. [Note: My screenshot is showing Create Unit Test in singular because I had previously tried to rename it]. Then click Close.

Restart Visual Studio 2012 and whalla! The context menu will be available!

 
Note: This apparently does not work in Visual Studio 2013.
 
Alternative is to use this Visual Studio Extension: Unit Test Generator
 
Advertisements

NUnit Setup In Visual Studio And Example NUnit test case

Once installed, Within Visual Studio, Tools | Nunitit | NUnitit settings

Change NUnit-GUI Executable to install path: C:\Program Files\NUnit 2.5.5\bin\net-2.0\nunit.exe

When you want to run an NUnit test, set the NUnit project in VS.NET as startup project and navigate to Tools | Debug Nunit GUI. The Nunit test interface will then load.

From there you can execute your test cases.

Very simple example of NUnit test:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using com.company.product.bl;

namespace com.company.product.nunit
{
    [TestFixture]
    public class TestJHAServiceManager
    {
        [Test]
        public void GetJHANames()
        {
            List<string> strings = JHAServiceManager.GetJHANames("jUnit");
            Assert.IsNotEmpty(strings);
        }


        /// <summary>
        /// Gets the JHA details with invalid id.
        /// Another example where an exception is expected
        /// </summary>
        [Test]
        [ExpectedException]
        public void GetJHADetailsWithInvalidId()
        {
            JobHazardAnalysis jha = new JobHazardAnalysis()
            {
                Id = -25
            };
            jha.LoadDetails();
        }

    }
}

Excluding A Web Site From Building When Debugging (F5)

From Jared:

Inline code is great.

You can update any site by just pushing out one file with your code in it, and all references to that file are set. However, the downside is that the capability that allows you to do that (on-demand compiling) is the same thing that holds you back when debugging if you compile the site before debugging (which is the default).

Output Window

Even worse… debugging makes you compile every site, most of which aren’t even relevant to your test.

Luckily there’s an easy way around this.

1. Go to the property pages of your site (Solution Explorer > Right-click solution > Property Pages…).
2. On the “Build” tab, set the “Before running startup page” action to “No Build”

No Build

Do this for every web site in your solution except the one your localhost is set to. This should cut wait time down dramatically.