How can I get the name DeploymentItem?

I would like to get rid of some duplication in this code. Following the principle of DRY.
As you can see, the file name / deploymentItem is repeated.

[TestMethod] [DeploymentItem("TestData/TestExcel.xlsx")] <-- public void GivenAnExcel_ConverToPDF() { const string filename = "TestData/TestExcel.xlsx"; <-- var result = pdfConverter.ConvertExcelDocument(filename); AssertIsPdf(result); } 
  • Is there a way to access DeploymentItem programmatically without using a file name?
    Or
  • Can I get the file name programmatically?

No, I cannot use a different test structure than mstest ;-)

+4
source share
1 answer

You could just do this:

 [TestClass] public class Test { const string filename = "TestData/TestExcel.xlsx"; [TestMethod] [DeploymentItem(filename)] public void GivenAnExcel_ConverToPDF() { var result = pdfConverter.ConvertExcelDocument(filename); AssertIsPdf(result); } } 
+4
source

Source: https://habr.com/ru/post/1445709/


All Articles