使用NUnit,我希望能够写一个测试夹具将读取所有的文件名在一个特定的目录,并创建一个测试为每个文件。
Using Nunit, I want to be able to write a test fixture that will read all the filenames in a particular directory and create a test for each file.
我可以非常容易地编写一个测试方法,它通过扫描目录,只是做了所有的测试,但是当我运行NUnit的我希望能够单独看每一次试验。
I could quite easily write one test method that scans through the directory and just does all the tests, but when I run NUnit I want to be able to see each of the tests individually.
这甚至可能吗?
推荐答案
我已经找到了适合我的目的的方法
I've found a way that fits my purposes
有一个测试用例,并与TestCaseSource标记属性,像这样
Have one test case, and mark it with the TestCaseSource attribute like so
[Test, TestCaseSource("GetTestCases")]
public void TestFile(string filename)
{
//do test
}
然后写GetTestCases读取所有的文件名中的目录
Then write the GetTestCases to read all the file names in the directory
private static string[] GetTestCases()
{
return GetAllFilesInCurrentDirectory();
}
后来,当我开始NUnit的我得到的测试列表来运行(上市TESTFILE下)。
Then when I start NUnit I get a list of the tests to be run (listed under TestFile).
相关推荐
最新文章