Dynamically create tests in NUnit

后端 未结 4 1126
被撕碎了的回忆
被撕碎了的回忆 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:06

    If you are not going to be adding files to that directory over time and have a set of filenames to pass in as an input to a generic test, try using the RowTest NUnit extension (part of the std distrib post v2.4.7) - You'd be able to see each test case - input combination individually in the GUI grouped under a single node.

    If you are going to be adding files to that directory, I'd write a single NUnit TestCase that loops over a list of files obtained at runtime and calls the generic test method with each filepath. Use a collecting parameter to collect failing test file names - at the end you assert. You wouldn't be able to see each test case individually but you'd have readable simple test code.

    Assert.AreEqual(listOfFailedFiles.Length, 0, PrettyPrint(listOfFailedFiles))
    

提交回复
热议问题