Making One Unit Test Count as Several
Using Visual Studio Test Suite, is there a way to make a single unit test behave and give results as if it were several tests?
I would like to have a test for each set of input parameters I will provide. But I'd rather have all the var开发者_Python百科ieties of input be data-driven, rather than having to write a seperate test for each one.
This question is similar to this one except that (1) I'm not using NUnit and (2) I might prefer my test data comes from a file (a file having data representing many tests).
MSTest doesn't have the RowTest as in other xUnit frameworks. However it does seem to have a feature for data-driven tests (that get their data from a DB/Xml/Csv file.) Its a case of simple things aren't possible... complex things are.
Actually this question might be a dupe of
MSTest Equivalent for NUnit's Parameterized Tests?
How to RowTest with MSTest?
Have you considered putting the actual test code in a separate, private method with parameters, then create multiple test methods that each just pass different parameters into the private method?
Asserts and such will still work.
Even though it's a test assembly, you can still create whatever support classes and methods you need to support your tests.
Unit tests are classes.
They can be instantiated and subclassed.
A test can (and sometimes should) have a "fixture" -- a file of source data.
精彩评论