MsTest, DataSourceAttribute - how to make it work with the generated file at runtime?

for some test, I need to run a data driven test with the configuration that is generated (via reflection) in the ClassInitialize method (using reflection). I tried everything, but I just can’t set up the data source correctly.

The test takes a list of classes in the csv file (one line for each class), and then checks that the mappings in the database work well (i.e. try to get one element from the database for each entity, an exception if the table structure does not match )

Test method:

[DataSource( "Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\EntityMappingsTests.Types.csv", "EntityMappingsTests.Types#csv", DataAccessMethod.Sequential) ] [TestMethod()] public void TestMappings () { 

Obviously, the EntityMappingsTests.Types.csv file. It must be in the DataDirectory.

Now, in the Initialize method (marked by ClassInitialize), I put this together and then try to write it.

WHERE should I write it? WHERE IS THE HISTORY OF DataDirectory?

I tried:

 File.WriteAllText(context.TestDeploymentDir + "\\EntityMappingsTests.Types.csv", types.ToString()); File.WriteAllText("EntityMappingsTests.Types.csv", types.ToString()); 

Both results lead to the fact that "the unit test adapter could not connect to the data source or read the data." More precisely:

Error Details: The Microsoft Jet database engine could not find object 'EntityMappingsTests.Types.csv'. Make sure that the object exists and that you correctly name its name and path name.

So where should I put this file?

I also tried just writing it to the current directory and taking out the DataDirectory part - the same result. Unfortunately, there is limited debugging support here.

+6
source share
2 answers

Please use the ProcessMonitor tool from technet.microsoft.com/en-us/sysinternals/bb896645 . Place the filter on MSTest.exe or the associated qtagent32.exe file and find out in what places it is trying to download and at what point in time the test loading process is undergoing. Then, please provide information on these details.

+5
source

After adding the CSV file to the VS project, you should open the properties for it. Set the Copy to Output Directory property to Always Copy. By default, the DataDirectory corresponds to the location of the compiled executable that runs from the output directory to find it there.

+1
source

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


All Articles