NUnit 测试用例生成:如何创建子文件夹(层次结构)?

发布于 2024-12-14 21:16:02 字数 488 浏览 6 评论 0原文

我正在根据文件名生成 NUnit 测试用例。

该目录如下所示:

Customer
    CustomerTestCase1.xml
    CustomerTestCase2.xml

Account
    AccountTestCase1.xml
    AccountTestCase2.xml

我正在使用 TestCaseSource:

    string[] list = Directory.GetFiles(path, "*", SearchOption.AllDirectories)

    foreach (string file in list)
    {
        yield return new TestCaseData(file)
    }

如何将层次结构引入生成的测试用例?我需要根据文件夹结构将它们组织成组,因此我可以勾选“帐户”,然后将选择所有帐户测试用例。

I am generating NUnit testcases based on the file names.

The directory looks like this:

Customer
    CustomerTestCase1.xml
    CustomerTestCase2.xml

Account
    AccountTestCase1.xml
    AccountTestCase2.xml

I am using TestCaseSource:

    string[] list = Directory.GetFiles(path, "*", SearchOption.AllDirectories)

    foreach (string file in list)
    {
        yield return new TestCaseData(file)
    }

How do I introduce hierarchy into the generated testcases? I need them to be organized in groups according to folder structure, so I could tick "Account" and all the account testcases would be selected.

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

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

发布评论

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

评论(1

孤芳又自赏 2024-12-21 21:16:02

Charlie Poole @ NUnit-讨论

Hi Andrey,

如果该结构是动态的,那么您无能为力。然而,
如果结构没有改变,那么你可以简单地编写多个
固定装置,并进行从不同来源获取数据的测试。

所以你可能有一个客户固定装置,从某些地方提取测试数据
特定的一个或多个源,以及提取其数据的帐户固定装置
来自其他来源。

将这些灯具的通用代码放入基类中,以便
你不必重复这个逻辑。事实上,应该很容易
直接从您必须使用基类的内容进行重构
然后为您想要的测试创建单独的叶类
分别选择。

查理

http://groups.google.com/group/nunit-discuss/ browser_thread/thread/543102e801511c41

Charlie Poole @ NUnit-Discuss

Hi Andrey,

If that structure is dynamic, then there is little you can do. However,
if the structure does not change, then you can simply code multiple
fixtures, with tests that take data from different sources.

So you might have a Customer fixture, pulling test data from some
particular source or sources, and an Account fixture pulling its data
from other sources.

Put the common code for these fixtures into a base class so that
you don't have to repeat the logic. In fact, it should be easy to
refactor directly from what you have to use of a base class and
then to create separate leaf classes for the tests you want to
select separately.

Charlie

http://groups.google.com/group/nunit-discuss/browse_thread/thread/543102e801511c41

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