MsTest,DataSourceAttribute-如何使其与运行时生成的文件一起使用? [英] MsTest, DataSourceAttribute - how to get it working with a runtime generated file?

查看:260
本文介绍了MsTest,DataSourceAttribute-如何使其与运行时生成的文件一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于某些测试,我需要使用在ClassInitialize方法(通过使用反射)中生成(通过反射)的配置来运行数据驱动的测试.我尝试了所有操作,但无法正确设置数据源.

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

该测试获取一个csv文件中的类列表(每个类一行),然后测试到数据库的映射是否工作良好(即,尝试从数据库中为每个实体获取一项,这将抛出表结构不匹配时出现异常).

The test takes a list of classes in a csv file (one line per class) and then will test that the mappings to the database work out well (i.e. try to get one item from the database for every entity, which will throw an exception when the table structure does not match).

测试方法是:

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

显然,该文件是EntityMappingsTests.Types.csv.它应该在DataDirectory中.

Obviously the file is EntityMappingsTests.Types.csv. It should be in the DataDirectory.

现在,在Initialize方法(标记为ClassInitialize)中,将它们放在一起,然后尝试编写.

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

我应该在哪里写?数据目录在哪里?

WHERE should I write it to? WHERE IS THE DataDirectory?

我尝试过:

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

这两种结果均导致单元测试适配器无法连接到数据源或读取数据".更确切地说:

Both result in "the unit test adapter failed to connect to the data source or read the data". More exact:

错误详细信息:Microsoft Jet数据库引擎找不到 对象"EntityMappingsTests.Types.csv".确保对象存在 并正确拼写了它的名称和路径名.

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

那我应该把那个文件放在哪里?

So where should I put that file?

我还尝试将其写入当前目录并取出DataDirectory部分-相同的结果.遗憾的是,这里的调试支持有限.

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

推荐答案

请使用 technet.microsoft .com/en-us/sysinternals/bb896645 .在MSTest.exe或关联的qtagent32.exe上放置一个筛选器,找出它试图从哪个位置加载以及在测试加载过程中的哪个时间点.然后,请在此处提供有关这些详细信息的更新.

Please use the ProcessMonitor tool from technet.microsoft.com/en-us/sysinternals/bb896645. Put a filter on MSTest.exe or the associate qtagent32.exe and find out what locations it is trying to load from and at what point in time in the test loading process. Then please provide an update on those details here .

这篇关于MsTest,DataSourceAttribute-如何使其与运行时生成的文件一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆