是否可以针对特定(长)测试列表运行 NUnit

发布于 2024-11-30 08:16:46 字数 370 浏览 1 评论 0原文

我有一个要运行的数千个 NUnit 测试列表(由另一个工具自动生成)。 (这是所有测试的子集,并且经常更改)

我希望能够通过 NUnit-Console.exe 运行这些测试。 不幸的是, /run 选项仅采用直接的文件列表,在我的情况下,这些文件不适合单个命令行。我希望它从文件名中获取列表。

我很高兴我可以使用类别,但我想要运行的列表经常更改,因此我不想开始更改源代码。

有谁知道是否有一种干净的方法让 NUnit 运行我指定的测试? (我可以使用完整的命令行将其分解为一系列对 NUnit 控制台的较小调用,但这不是很优雅)

(如果不可能,也许我应该将其添加为 NUnit 功能请求。)

I have a list of several thousand NUnit tests that I want to run (generated automatically by another tool). (This is a subset of all of the tests, and changes frequently)

I'd like to be able to run these via NUnit-Console.exe. Unfortunately the /run option only takes a direct list of files which in my case would not fit on a single command line. I'd like it to pickup the list from a filename.

I appreciate that I could use categories, but the list I want to run changes frequently and so I'd prefer not to have to start changing source code.

Does anyone know if there is a clean way to get NUnit to run my specified tests?
(I could break it down into a series of smaller calls to NUnit-console with a full command line, but that's not very elegant)

(If it's not possible, maybe I should add it as an NUnit feature request.)

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

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

发布评论

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

评论(3

手长情犹 2024-12-07 08:16:47

Charlie Poole(来自 NUnit 开发团队)回复说,这目前不可能,但已作为 NUnit 2.6 的功能请求添加

Had a reply from Charlie Poole (from NUnit development team), that this is not currently possible but has been added as a feature request for NUnit 2.6

佼人 2024-12-07 08:16:47

我明白你在说什么,但就像你说的,你可以从命令行运行单个装置。

nunit-console /fixture:namespace.fixture tests.dll

在同一个夹具中生成所有测试怎么样?或者将它们全部放在同一个组件中?

nunit-console tests.dll

I see what you're saying, but like you say you can run a single fixture from the command line.

nunit-console /fixture:namespace.fixture tests.dll

How about generating all the tests in the same fixture? Or place them all in the same assembly?

nunit-console tests.dll
书间行客 2024-12-07 08:16:47

正如 nunitLink 中提到的,我们需要提到场景/测试用例名称。它很简单,但其中有一些技巧。直接提及测试用例名称不会达到目的,您最终将执行 0 个测试用例。我们需要为其编写确切的路径。

我不知道它如何适用于其他语言,但使用 c# 我找到了解决方案。每当我们创建功能文件时,都会在 Visual Studio 中创建相应的 feature.cs 文件。单击 featureFileName.feature.cs 并查找名称空间并将其放在一边(第 1 部分)

namespace MMBank.Test.Features

向下滚动一点,您将获得类名称。请注意,并将其放在一边(第 2 部分)

public partial class HistoricalTransactionFeature

继续向下滚动,您将看到 nunit 基本上可以理解执行的代码。

[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("TC_1_A B C D")]
[NUnit.Framework.CategoryAttribute("MM_Bank")]

在代码下方,您可以看到函数/方法名称,很可能是 TC_1_ABCD(某些参数)

public virtual void TC_1_ABCD(string username, string password, string visit)

您将拥有多个基于 no 的此类方法。您的功能文件中的场景。记下要执行的方法(测试用例)并将其放在一边(第 3 部分)

现在用点整理所有部分。最后你会得到这样的结果,

MMBank.Test.Features.HistoricalTransactionFeature.TC_1_ABCD

就是这样。同样,您可以从多个功能文件创建测试用例名称并将它们堆叠在文本文件中。每个测试用例名称应该位于不同的行中。对于命令,您可以浏览上面的 nunit 链接以使用命令提示符执行。

As mentioned in the nunitLink, we need to mention the scenario/test case name. It simple but it has bit of a trick in it. Directly mentioning the test case name will not serve the purpose and you will end up with the 0 testcases executed. We need to write the exact path for the same.

I don't know how it works for other languages but using c# I have found a solution. Whenever we create a feature file corresponding feature.cs file get's created in Visual Studio. Click on the featureFileName.feature.cs and look for namespace and keep it aside(Part 1)

namespace MMBank.Test.Features

Scroll a bit down you will get the class name. Note that as well and keep it aside(Part 2)

public partial class HistoricalTransactionFeature

Keep scrolling down, you will see the code which nunit understands for execution basically.

[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("TC_1_A B C D")]
[NUnit.Framework.CategoryAttribute("MM_Bank")]

Below the code you can see the function/method name which will most likely be TC_1_ABCD(certain parameters)

public virtual void TC_1_ABCD(string username, string password, string visit)

You will be having multiple such methods based on no. of scenarios you have in your feature file. Note the method(test case) which you want to execute and keep it aside(Part 3)

Now collate all the parts with dots. Finally you will land up with something like this,

MMBank.Test.Features.HistoricalTransactionFeature.TC_1_ABCD

This is it. Similarly you can create the test case names from multiple feature files and stack them up in text file. Every test case name should be in different line. For command you can browse through above nunit link for execution using command prompt.

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