47

Does Visual C# 2010 Express have a unit testing feature?

9 Answers 9

38

As has been stated, the Express versions do not have any built-in, and do not allow add-ins for, this functionality, but you can use an external tool, e.g. NUnit.

You can also set up a command to run from the 'Tools->External Tools' menu option from within Visual Studio Express and run your test runner from that if you wish.

Here is a link that shows how to do it with VS C# 2008 Express, (scroll down to the end) but I think it should hold true for 2010 as well.

Here is a new working link.

2
  • 2
    Also, opening (an already open in VS Express) project in Sharpdevelop 4.0 will give an ability to run tests "visually" (the their results tied to source code) and possibly make some quick modifications to code (which will be correctly recognized by VS Express when you Alt_Tab back to it). So, the price of having a usable "visual" unit-tesing feature is about one extra Alt-Tab to SharpDevelop (and may be a click on "Run Tests").
    – mlvljr
    Commented Mar 6, 2011 at 13:09
  • NB this won't work for VS Express for Windows Phone unless the external tool is specifically compiled for it...
    – funkybro
    Commented Oct 12, 2011 at 13:44
10

Nothing built in, but you can always use nUnit with it.

MSTest comes bundled with the Pro edition and above.

9

In 2010 it's possible using an external application, however debugging unit tests becomes difficult. If you want debugging using NUnit is probably the best route (but not the only option, see ExpressUnit). See this answer on another SO thread. It links to a blog that mentions running the test project as a console application and calling the nunit library dlls directly to launch the tests:

using System;

namespace RunTests
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            var args = new string[] { Assembly.GetExecutingAssembly().Location, "/run" };
            NUnit.Gui.AppEntry.Main(args);
        }
    }
}
1
  • 404 on the blog post. This is a great way to debug unit tests in the UI. Thanks for sharing. I ended up creating a separate project, adding a reference to the assemblies that I want to test, then using Assembly.GetAssembly( typeof(MyAssembly.MyType)).Location to source the assembly to the test runner.
    – cod3monk3y
    Commented Mar 6, 2014 at 17:57
8

Visual Studio Express editions have the limitation that plugins/addins are expressely disallowed. They do not ship with a built-in testing solution, and you cannot add-in one.

Your best/only option it to use a standalone test runner, such as nUnit, mspec, etc... and run it externally from VSE.

7

This is now included in Visual Studio 2013 Express: http://msdn.microsoft.com/en-us/library/dd264975.aspx

If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer.

enter image description here

4
  • It's so sad to see M$ jumping on this "testing" bandwagon just because everyone else is doing it. What a fad. (Seriously, this is 2013 and we're just getting integrated unit testing in VS??)
    – cod3monk3y
    Commented Mar 6, 2014 at 0:18
  • 2
    @cod3monk3y, what a strange comment. It's a shame it took so long but surely it's in improvement? I'd hardly describe testing as a fad!
    – matt burns
    Commented Mar 6, 2014 at 6:51
  • 1
    Absolutely it's an improvement! I've been developing in C# for over a decade and I'm a huge proponent of unit testing, code coverage, process, etc. So, the comment was begrudgingly sarcastic. Testing should be integral to the development process and I'm happy to see it finally become a base feature for all developers to share. I've lately been doing some Python and Angular/JS/Flask/Python programming and love how unit testing is part of the culture (python -m unittest discover for python and jasmine/karma for JS). Glad to see this as part of the new developers' toolkit.
    – cod3monk3y
    Commented Mar 6, 2014 at 17:42
  • This does not work in express versions. The link says nothing about express, only full versions
    – SwDevMan81
    Commented Aug 11, 2016 at 23:11
1

As an update, I am currently using Visual Studio Express for Desktop, the VS suite has been completely remodelled since 2010 and more accurately reflects the "big brother".

Unit tests are now available as a built-in feature and works the same way (I haven't tested all functionality) as Visual Studio non-Express.

0

Have a look at NHarness at codeplex, a very simple library that allows you to run NUnit test fixtures in a test project. This allows you the ability to debug through your unit tests if required

An example (from the codeplex page) of a test runner is as below

    public class RunTests
    {
        public static void Main(string[] args)
        {
            TestResults results = Tester.RunTestsInClass<Tests>();

            Console.WriteLine("Tests Run: {0}", results.NumberOfResults);
            Console.WriteLine("Results {0}:PASSED {1}:FAILED", results.NumberOfPasses, results.NumberOfFails);
            Console.WriteLine("Details:");

            foreach (TestResult result in results)
            {
                Console.WriteLine("Test {0}: {1} {2}",
                                            result.MethodName,
                                            result.Result,
                                            result.Result == TestResult.Outcome.Fail ? "\r\n" + result.Message : "");
            }

            Console.ReadLine();
        }
    }

The benefit of this library is that the TestResults class can be used to retrieve information about the tests executed, so the library can also be used in custom unit test applications

0

You could always set up an additional class with a Main() method in the project and select it as a startup object in your project, and debug it from there. It might not be suitable in situation where more complex tasks is done, since you can't take advantage of the more testing-specific features but it might be useful in some simpler projects. If your project is a class library, consider convert it to an console application and then switch it back when you finished testing.

0

(Note : I know this post is old, but this might help someone )

As Andy posted above, you can use NUnit .
But the settings in the link posted by Andy do not work anymore in VS C# 2010.
Here are the settings I use in the External Tools window :

Command : C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-x86.exe
( there is also a nunit.exe in the bin directory )

Arguments : $(ProjectDir)$(ProjectFileName)
Initial directory : $(ProjectDir)bin/Debug/$(TargetName)$(TargetExt)

Not the answer you're looking for? Browse other questions tagged or ask your own question.