Search code examples
nunitautomated-teststestcase

Dynamic test cases


We are using NUnit to run our integration tests. One of tests should always do the same, but take different input parameters. Unfortunately, we cannot use [TestCase] attribute, because our test cases are stored in an external storage. We have dynamic test cases which could be added, removed, or disabled (not removed) by our QA engineers. The QA people do not have ability to add [TestCase] attributes into our C# code. All they can do is to add them into the storage.

My goal is to read test cases from the storage into memory, run the test with all enabled test cases, report if a test case is failed. I cannot use "foreach" statement because if test case #1 is failed, then rest of the test cases will not be run at all. We already have build server (CruiseControl.net) where generated NUnit reports are shown, therefore I would like to continue using NUnit.

Could you point to a way how can I achieve my goal? Thank you.


Solution

  • You can use [TestCaseSource("PropertyName")\] which specifies a property (or method etc) to load data from.

    For example, I have a test case in Noda Time which uses all the BCL time zones - and that could change over time, of course (and is different on Mono), without me changing the code at all.

    Just make your property/member load the test data into a collection, and you're away.

    (I happen to have always used properties, but it sounds like it should work fine with methods too.)