使用文件夹结构和 XML 文件在 NUnit 中动态生成测试装置和测试用例
我正在尝试根据包含 XML 文件的文件夹结构动态生成测试。 (测试使用 XML 文件来驱动 Selenium RC)
举例来说,我有 3 个文件夹,其中还包含子文件夹(每个文件夹都包含我用来驱动 Selenium RC 的 Data.xml 文件)
TestData
TestFixtureOne
TestCaseOne
Data.xml
TestCaseTwo
Data.xml
TestCaseThree
Data.xml
TestFixtureTwo
TestCaseOne
Data.xml
TestCaseTwo
Data.xml
TestFixtureThree
TestCaseOne
Data.xml
TestCaseTwo
Data.xml
TestCaseThree
Data.xml
TestCaseFour
Data.xml
TestCaseFive
Data.xml
我当前拥有的代码如下
using System;
using System.Text;
using System.Threading;
using NUnit.Framework;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
namespace NUnitIntegration
{
[TestFixture]
class SeleniumTest
{
private static string testDirectory;
public SeleniumTest()
{
testDirectory = ConfigurationManager.AppSettings["TestDirectory"]; // Let’s assume this value is “C:\TestData\”
}
[SetUp]
public void init()
{
// Nothing needed as of yet
}
[Test, TestCaseSource("GetTestCases")]
public void TestSource(string test)
{
System.Console.WriteLine("Successfully executed test for: " + test);
}
[TearDown]
public void dispose()
{
// Nothing needed as of yet
}
private static string[] GetTestCases()
{
return getTests();
}
private static string[] getTests()
{
return Directory.GetDirectories(testDirectory);
}
}
}
但这只会带回 TestFixtureOne、TestFixtureTwo 和 TestFixtureThree 文件夹(见下文),这不是我想要的。我试图使其灵活,以便我可以在需要时添加更多测试(更多 TestFixtures 和 TestCases)。
[NUnit 测试树] 测试源 测试夹具一 测试夹具二 TestFixtureThree
我最近进行了不懈的搜索,发现了这些对我很有帮助的线程,但现在我陷入了困境!
用于多个 [TestFixture] (以及我从中获得上述代码的另一个线程)
任何帮助将不胜感激,
问候
I am trying to generate tests dynamically based on the structure of folders that contain XML files. (The tests use the XML files to drive Selenium RC)
So say for example I have 3 Folders which also contain sub folders (each of which contain the Data.xml file I use to drive selenium RC)
TestData
TestFixtureOne
TestCaseOne
Data.xml
TestCaseTwo
Data.xml
TestCaseThree
Data.xml
TestFixtureTwo
TestCaseOne
Data.xml
TestCaseTwo
Data.xml
TestFixtureThree
TestCaseOne
Data.xml
TestCaseTwo
Data.xml
TestCaseThree
Data.xml
TestCaseFour
Data.xml
TestCaseFive
Data.xml
The code I currently have is like so
using System;
using System.Text;
using System.Threading;
using NUnit.Framework;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
namespace NUnitIntegration
{
[TestFixture]
class SeleniumTest
{
private static string testDirectory;
public SeleniumTest()
{
testDirectory = ConfigurationManager.AppSettings["TestDirectory"]; // Let’s assume this value is “C:\TestData\”
}
[SetUp]
public void init()
{
// Nothing needed as of yet
}
[Test, TestCaseSource("GetTestCases")]
public void TestSource(string test)
{
System.Console.WriteLine("Successfully executed test for: " + test);
}
[TearDown]
public void dispose()
{
// Nothing needed as of yet
}
private static string[] GetTestCases()
{
return getTests();
}
private static string[] getTests()
{
return Directory.GetDirectories(testDirectory);
}
}
}
But this will only bring me back the TestFixtureOne, TestFixtureTwo, and TestFixtureThree folders (see below) which is not what I am after. I was trying to make it flexible so that I can added more tests if needed (more TestFixtures and TestCases).
[NUnit Test Tree]
TestSource
TestFixtureOne
TestFixtureTwo
TestFixtureThree
I have searched quite relentlessly recently and came across these threads which helped me very much, but now I am stuck!
used in multiple [TestFixture]s
(And another thread where I got the above code from)
Any help would be greatly appreciated,
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是否需要使用 GetFiles() 方法来获取 XML 文件,但要递归地获取目录,您可以使用
有关此函数的更多信息 此处。
I'm not sure whether you need to use the GetFiles() method to get the XML files, but to get the directories recursively you could use
More information on this function here.