Visual C# 2010 Express 中的单元测试?

发布于 2024-09-13 08:33:24 字数 41 浏览 6 评论 0 原文

Visual C# 2010 Express 是否具有单元测试功能?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

许久 2024-09-20 08:33:28

没有内置任何内容,但您始终可以将 nUnit 与它一起使用。

MSTest 与 Pro 版及更高版本捆绑在一起。

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

MSTest comes bundled with the Pro edition and above.

匿名。 2024-09-20 08:33:28

2010 年可以使用外部应用程序,但是调试单元测试变得很困难。如果您想使用 NUnit 进行调试可能是最好的途径(但不是唯一的选择,请参阅 ExpressUnit)。请参阅另一个 SO 线程上的答案。它链接到 博客,其中提到将测试项目作为控制台应用程序运行并调用 nunit直接使用库 dll 来启动测试:

using System;

namespace RunTests
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            var args = new string[] { Assembly.GetExecutingAssembly().Location, "/run" };
            NUnit.Gui.AppEntry.Main(args);
        }
    }
}

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);
        }
    }
}
鹊巢 2024-09-20 08:33:28

Visual Studio Express 版本有明确禁止使用插件/插件的限制。它们不附带内置测试解决方案,您也无法添加测试解决方案。

您最好/唯一的选择是使用独立的测试运行程序,例如 nUnit、mspec 等...并从 VSE 外部运行它。

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.

安静被遗忘 2024-09-20 08:33:28

现在它包含在 Visual Studio 2013 Express 中:
http://msdn.microsoft.com/en-us/library/dd264975.aspx

如果测试资源管理器不可见,请选择视觉对象上的测试
Studio 菜单,选择Windows,然后选择测试资源管理器

在此处输入图像描述

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

剪不断理还乱 2024-09-20 08:33:28

作为更新,我目前使用的是 Visual Studio Express for Desktop,VS 套件自 2010 年以来经过了彻底改造,更准确地体现了“老大哥”。

单元测试现在作为内置功能提供,其工作方式与 Visual Studio 非 Express 相同(我尚未测试所有功能)。

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.

深空失忆 2024-09-20 08:33:28

查看 codeplex 上的 NHarness,这是一个非常简单的库,允许您在测试项目中运行 NUnit 测试装置。这使您能够在需要时通过单元测试进行调试。

测试运行程序的示例(来自 codeplex 页面)如下所示。

    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();
        }
    }

该库的好处是 TestResults 类可用于检索有关所执行测试的信息,因此该库还可以用于自定义单元测试应用程序

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

北城孤痞 2024-09-20 08:33:28

您始终可以在项目中使用 Main() 方法设置一个附加类,并将其选择为项目中的启动对象,然后从那里调试它。它可能不适合完成更复杂的任务的情况,因为您无法利用更多特定于测试的功能,但它可能在一些更简单的项目中有用。如果您的项目是类库,请考虑将其转换为控制台应用程序,然后在完成测试后将其切换回来。

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.

避讳 2024-09-20 08:33:28

(注意:我知道这篇文章很旧,但这可能会对某人有所帮助)

正如安迪在上面发布的那样,您可以使用 NUnit .
但 Andy 发布的链接中的设置在 VS C# 2010 中不再起作用。
以下是我在“外部工具”窗口中使用的设置:

命令: C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-x86.exe
bin 目录中还有一个 nunit.exe

参数: $(ProjectDir)$(ProjectFileName)
初始目录: $(ProjectDir)bin/Debug/$(TargetName)$(TargetExt)

(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)

-残月青衣踏尘吟 2024-09-20 08:33:27

如前所述,Express 版本没有任何内置功能,也不允许使用插件来实现此功能,但您可以使用外部工具,例如 NUnit.

您还可以设置一个命令,从 Visual Studio Express 中的“工具 -> 外部工具”菜单选项运行,并根据需要运行您的测试运行程序。

这里是一个链接,展示了如何使用 VS C# 2008 Express 执行此操作(向下滚动到末尾),但我认为它也应该适用于 2010 年。

这是一个新的工作链接。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文