数据驱动的单元测试-CSV编码有问题吗? [英] Data-driven unit testing - Problem with CSV encoding?

查看:115
本文介绍了数据驱动的单元测试-CSV编码有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据驱动的单元测试中使用了以下CSV文件:

I have the following CSV file that is used in my data-driven unit test:

File;expected
Resources.resx;default
Resources.de.resx;de
AttachmentDetail.ascx.it.resx;it
SomeOtherFile.rm-CH.resx;rm-CH

文件"和预期"是标题.但是,如果我想在类似的代码中获取文件"列

"File" and "expected" are the header. But if I want to get the "File"-column in the code like

TestContext.DataRow["File"].ToString();

我得到了错误

System.ArgumentException:列 文件"不属于表..

System.ArgumentException: Column 'File' does not belong to table ..

当我通过test-method属性将CSV文件添加到现有的测试用例中时,"File"列似乎在其名称之前有一些奇怪的标志,就像编码问题一样.但是,如果我使用记事本,记事本++或什至是TextMate(在Mac上)打开CSV文件,则看不到任何此类迹象,而且我也无法摆脱.

When I add the CSV file to an existing test-case over the test-method properties, it seems as if the "File"-column has some strange signs before its name, much like an encoding problem. But if I open the CSV file with Notepad, Notepad++ or even TextMate (on Mac) I don't see any such signs and I'm not able to get rid of them.

有人可以给我关于这个问题的建议吗?

Can someone give me a suggestion about this problem?

推荐答案

如果您在VS2008中编辑CSV文件,则可以设置保存CSV文件的方式:

If you edit the CSV file in the VS2008 you can set the way the CSV file will be saved:

文件\高级保存选项..."

"File\Advanced Save Options..."

在编码:"下拉列表中,默认值为UTF-8.将其更改为西欧(DOS)-代码页850".不用选择行尾".

In the "Encoding:" drop down the default will be UTF-8. Change it to "Wester European (DOS) - Codepage 850". Leave the Line endings selection alone.

这篇关于数据驱动的单元测试-CSV编码有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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