Dynamically create tests in NUnit

后端 未结 4 1124
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 07:27

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.

I could quite easily w

4条回答
  •  逝去的感伤
    2021-02-02 08:09

    I've found a way that fits my purposes

    Have one test case, and mark it with the TestCaseSource attribute like so

    [Test, TestCaseSource("GetTestCases")]
    public void TestFile(string filename)
    {
        //do test
    }
    

    Then write the GetTestCases to read all the file names in the directory

    private static string[] GetTestCases()
    {
        return GetAllFilesInCurrentDirectory();
    }
    

    Then when I start NUnit I get a list of the tests to be run (listed under TestFile).

提交回复
热议问题