CSV提供的数据源第一列中的奇数字符 [英] Odd character in first column of datasource provided by CSV
问题描述
我有一个CSV文件,该文件已添加到Visual Studio单元测试项目中.它有七列,看起来像这样:
I've got a CSV file that I added to a Visual Studio Unit Test project. It has seven columns and looks like this:
assessmentitemid,reviewer1,reviewer2,reviewer3,reviewer4,reviewer5,reviewer6
我的测试方法如下:
[TestMethod]
[DeploymentItem("IntraclassCorrelationValues.csv")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\IntraclassCorrelationValues.csv", "IntraclassCorrelationValues#csv", Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod.Sequential)]
public void TestMethod1() {
object val = TestContext.DataRow["assessmentitemid"];
}
访问列Evaluationitemid时抛出错误.我检查了表格,除评估项目之外,所有列均已正确映射.其实际的列名称是这样的:
I get an error thrown when accessing the column assessmentitemid. I checked the table and all the columns are mapped properly except for the assessmentitemid. Its actual column name is this:
assessmentitemid
为了使DataSource属性正确解析CSV文件,我还需要做其他事情吗?
Is there something else I have to do to the DataSource attribute in order for it to parse the CSV file correctly?
推荐答案
.csv文件可能具有Unicode编码.
Looks like the .csv file may have Unicode encoding.
尝试在记事本中打开它,然后在另存为"下,选择UTF-8或ANSI.
Try opening it in Notepad and under 'Save As', select UTF-8, or ANSI instead.
这篇关于CSV提供的数据源第一列中的奇数字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!