I am interested in the possibility of creating several test cases with constructor arguments passed to it at run time by a static method or by a property that returns IEnumerable.
In Nunit 2.5, they introduced parameterized tests and test instruments. This allows you to write one test and run it with several inputs provided using the TestCase attribute, and write one test class and create several instances of it with different constructor arguments, respectively.
In addition to this, you can create several test cases based on the output of a property or method using the TestCaseSource attribute. This will use the output of the method / property that IEnumerable implements to create a set of test tables, one per object in the list. This is what I would like to do, but at the instrument level is not the test level.
Some prerequisites for my use:
I am testing a simulation software and a "simulation environment" that must be loaded (from a serialized object) before any simulations can be run. There are about 5 different sim types, so my test class has 5 test methods (one for each sim type). I use inheritance now (instead of parameterized devices) to run test cases in several (half a dozen or so) simulation environments that were taken from production data.
My problem is that in a recent attempt to increase the reach of the code, we automatically generated all possible combinations of modeling components, which led to the creation of more than 100 characters. I don’t want to create inherited classes for each of them, so instead I use TestCaseSource with a property that returns all workspaces in the folder and modifies the tests so that they (re) load the sim environment in the test itself for each test file.
Ideally, I would like to have one fixture for each simulation environment and determine how many / what they are at runtime. I know that I can do the first by hard-coding the paths of the sim environment into 100+ TestFixture attributes, can I do the latter?
source share