Data driven unit tests with Text Files!!

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!

No comments:

Post a Comment

Latest Posts

Popular Posts