简体   繁体   中英

Class level DeploymentItem and DataSource

In my TestClass I have 6 test methods and for each test method I am using the same DeploymentItem and DataSource . Defining each time with each TestMethod is creating lots of redundancy in my code. Is it possible some how to define both of them one time for the complete TestClass ? I tried in ClassInitialize Attribute but could no achieve the the goal. Following is my DataSource and DeploymentItem detail:

[DataSource("CurrencyInfoList_DataSource")]
DeploymentItem("CoreUnitTests\\CurrencyUnitTests\\CurrencyTestData.xlsx")]

Simply enable deplyoment in your test settings and add the files you need to the settings, instead of adding them to each of the test methods.

See more details of how to achieve that here Do MSTest deployment items only work when present in the project test settings file?

Using the DeploymentItem attribute on the ClassInitialize method does not work. But instead, you can put it directly on your test class like so:

[TestClass()]
[DeploymentItem("MyFileToDeploy.txt")]
public class MyUnitTestClass
{
...
}

I'm not sure about DataSource , if that works as well. But probably it does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM