i wanted to do unit tests with a text file as input
1 line contains: entity serialized as string, entityName and other parameter
e.g.
1|12|123123,123123,143123|54| Riga1_GPS true
line is delimited by tab
#1
create file in your test project
righevalid.txt
File Properties: --> Copy to Output Directory --> copy always
#2
create file in your test project
schema.ini
File Properties: --> Copy to Output Directory --> copy always
#3
content of schema.ini
[righevalid.txt] Format=TabDelimited
#4
create testmethod
#5
add following attributes to testmethod
[TestMethod()] [DeploymentItem(@"righevalid.txt")] [DeploymentItem(@"schema.ini")] [DataSource("System.Data.OleDb", @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.;Extended Properties='text;FMT=TabDelimited;HDR=YES'", @"righevalid.txt", DataAccessMethod.Sequential)] public void LoadValidRigaTest() { }
Note DeploymentItem copies files to Test Run Directory
DataSource is a special OleDb Usage with txt Files
#6
use TestContext.DataRow[index] to access your single columns (line) of the text file
TestContext.DataRow[0] = col1 and so on
#7
Run Test
#8
see output Passed or Failed
Doubleclick Result you can see the result of the single lines!
GREAT!
Data driven unit tests with Text Files!!
Labels: .NET, unit tests, Vs2005, Vs2008
Latest Posts
Popular Posts
-
I am *very* keen on automating tests, so I was looking into unit testing a WCF service. If I say "unit test", I mean a fast ,...
-
It's easy I thought, just select the Property of the EntityType and set the Default Value in the Properties window to: DateTime.Now ...
-
*Updated* 26. September 2010: Updated with comments from Adam Cogan *Updated* 27. September 2010: Updated the comparison between anonymo...
No comments:
Post a Comment