Does Visua开发者_高级运维l C# 2010 Express have a unit testing feature?
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.
Nothing built in, but you can always use nUnit with it.
MSTest comes bundled with the Pro edition and above.
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);
}
}
}
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.
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.
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.
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
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.
(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)
精彩评论