I'm writing data driven unit tests using an Xml datasource in C# VS2008.
Attributes look something like this and everything works awesomely.
[DeploymentItem("HtmlSchemaUrls.xml")]
[DataSource("DataSource", "Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\HtmlSchemaUrls.xml", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, "URL")]
[DataBinding("DataSource", "URL", "URL_Text", "DataSource.URL.URL_Text")]
[TestMethod]
I'd like to extend the capabilities of the Microsoft.VisualStudio.TestTools.DataSource.XML datasource, preferrably configurable through App.config. For example, a bool when true I run through all the rows in the Xml file and when false I run through only one.
I do not want to perform this check in the test case itself - I have 1000s of test cases with this requirement.
Any guidance on how to achieve this would be most appreciated.
Use AssemblyInitialize to copy your XML test set from some test set repository.
1 - this way, you don't need [DeploymentItem("HtmlSchemaUrls.xml")]
2 - instead of just copying it, create a new file containing the records you need to test (using parameterized xsl ?)
3 - all parameters for that operation can be stored in your app.config
Shortened example (using simple copy to prepare the data driven test case env:
[AssemblyInitialize()]
public static void AssemblyInit(TestContext context)
{
...
string strRelocatedTestCaseFile =
Path.Combine(TheToolBox.ShortPath(AppDomain.CurrentDomain.BaseDirectory),
"TestCase.xml");
if(!string.IsNullOrEmpty(strTestCaseFile))
{
string strMessage = "Copying TestCase input file: '" +
strTestCaseFile + "' to '" + strRelocatedTestCaseFile + "'";
Console.WriteLine(strMessage);
File.Copy(strTestCaseFile, strRelocatedTestCaseFile, true);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With