[英].net unit test project with CSV datasource not reading in values correctly
I have a Unit Test project in .net 4.0. 我在.net 4.0中有一个单元测试项目。 One of the test methods reads in a CSV file.
测试方法之一是读取CSV文件。 Unfortunately, some of the values in the csv file are not being read.
不幸的是,csv文件中的某些值没有被读取。 I think what is happening is that .net is choosing what type a column is and ignoring any values that do not fit within that type.
我认为发生的情况是.net选择了列的类型,而忽略了该类型不适合的任何值。 For example, I may have a column where 90% of the values are numbers, but the other 10% are numbers with letters.
例如,我可能有一列,其中90%的值是数字,而其他10%是带字母的数字。 The numbers with letters are not coming through.
带字母的数字不通。 Any ideas on how to fix this?
有想法该怎么解决这个吗?
Here is the attribute on top of my test method 这是我的测试方法之上的属性
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\test.csv", "test#csv", DataAccessMethod.Sequential), DeploymentItem("MyProject.Tests\\TestData\\Test.csv"), TestMethod()]
Thanks! 谢谢! AFrieze
轻拂
You need to enclose the values in the mixed-type column in quotation marks. 您需要将值括在混合类型列中的引号中。 Eg
例如
AllNumeric,Mixed,AllString
1,"1",a
2,"2b",b
Alternatively, you can create a file named Schema.ini in the same directory as the csv file to specify the type, as mentioned below. 或者,您可以在与csv文件相同的目录中创建一个名为Schema.ini的文件以指定类型,如下所述。 http://geekswithblogs.net/dotNETvinz/archive/2011/01/03/uploading-and-importing-csv-file-to-sql-server-in-asp.net.aspx
http://geekswithblogs.net/dotNETvinz/archive/2011/01/03/uploading-and-importing-csv-file-to-sql-server-in-asp.net.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.