如何将单元测试作为构建的一部分运行(不是持续集成)

发布于 2024-12-11 11:01:30 字数 88 浏览 0 评论 0原文

我有 Nunit 单元测试,我需要将其作为 MS 构建的一部分运行。我知道运行所有测试会减慢构建速度,所以,我只需要运行受影响的测试,有什么办法可以找出答案。 。

I have Nunit unit test which i need to run as the part of my MS build.. I know that running all the test will slow up the build So, i need to run only the impacted test is there any way to find that out..

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

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

发布评论

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

评论(3

丑疤怪 2024-12-18 11:01:31

据我所知,对于 NUnit 测试来说,仅运行受影响的测试是不可能的。但这对于 Visual Studio 2010 Ultimate/Test Professional 中的 MSTest 是可能的:

推荐运行测试受代码更改影响的

您可以使用 Visual Studio Ultimate 或 Visual Studio Test Professional
2010 帮助您确定可能需要运行哪些测试,基于
对您正在测试的应用程序所做的编码更改。到
要使用此功能,您必须使用 Team Foundation
构建您的应用程序并使用 Microsoft Visual Studio 2010
用于源代码的版本控制

无论如何,您可以使用 MSBuild Community NUnit Task 从一组程序集运行测试。您可以通过指定 DependsOnTargets 属性将其作为标准 AfterBuild 目标的依赖目标来执行此操作。

<NUnit Assemblies="..."
       IncludeCategory="..."
       ExcludeCategory="..."
       ToolPath="$(NUnitDllsPath)"
       ProjectConfiguration="$(Configuration)"
       OutputXmlFile="$(NUnitOutputPath)\UnitTests.xml"
       ContinueOnError="true">

AFAIK running only impacted tests is not possible yet for NUnit tests. But this is possible for MSTests in Visual Studio 2010 Ultimate/Test Professional:

Recommending Tests to Run That are Affected by Code Changes

You can use Visual Studio Ultimate or Visual Studio Test Professional
2010 to help you determine which tests might have to be run, based on
coding changes that were made to the application you are testing. To
be able to use this functionality, you have to use Team Foundation
Build to build your application and use Microsoft Visual Studio 2010
for version control for your source code

Anyway you can use MSBuild Community NUnit Task to run tests from a set of the assemblies. You can do this as dependency target of standard AfterBuild target by specifying DependsOnTargets attribute.

<NUnit Assemblies="..."
       IncludeCategory="..."
       ExcludeCategory="..."
       ToolPath="$(NUnitDllsPath)"
       ProjectConfiguration="$(Configuration)"
       OutputXmlFile="$(NUnitOutputPath)\UnitTests.xml"
       ContinueOnError="true">
奈何桥上唱咆哮 2024-12-18 11:01:31

要了解受影响的测试,您需要跟踪测试用例代码覆盖率。只有这样,您才能检查哪些测试受到您所签入的更改的影响。除了 Microsoft 的 Team Foundation Server 之外,我不知道还有什么工具可以满足您的要求。

To know the impacted tests you need to track the test case code coverage. Only this way you can examine what test is impacted by the changes you are checking in. I don't know of any tool that does what you want besides Microsofts Team Foundation Server.

聊慰 2024-12-18 11:01:31

可以通过项目的“构建事件”属性来运行测试作为构建的一部分。您可以执行 NUnit 的命令行工具。

但正如 PVitt 已经指出的那样,我不知道 NUnit 是否可以与测试影响分析一起使用。

Running your tests as a part of the build can be done trough the Build Events properties of your project. You can execute the command line tool for NUnit.

But as PVitt already pointed out, I don't know if NUnit can work with Test Impact analysis.

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