0

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")]
Cosmin
  • 2,354
  • 2
  • 22
  • 39
IFlyHigh
  • 546
  • 2
  • 9
  • 20

2 Answers2

3

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.

Tobias
  • 2,089
  • 2
  • 26
  • 51
1

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?

Community
  • 1
  • 1
MichaC
  • 13,104
  • 2
  • 44
  • 56