You are on page 1of 12

Visual Studio Coded UI Tests Data-Driven Testing DDT

I n g . G o n za l o A l b a - M C P
2013

Data-Driven Testing
Data-Driven testing is when you store test data (input, expected output, etc.) in some external storage (like: databases, spreadsheet, xml files, csv files, etc.) and then use that data iteratively in your tests when running them.

Create Data-Driven Tests


Need to use [DataSourse] attribute Date Source Types: CSV Excel Test case in Team Foundation Server XML SQL Express

Data Source Attribute CSV


[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\data.csv", "data#csv", DataAccessMethod.Sequential), DeploymentItem("data.csv"), TestMethod]

Data Source Attribute Excel


[DataSource("System.Data.Odbc", "Dsn=Excel Files;Driver={Microsoft Excel Driver (*.xls)};dbq=|DataDirectory|\\Data.xls;defaultdir=.;driverid=790;maxbuf fersize=2048;pagetimeout=5;readonly=true", "Sheet1$", DataAccessMethod.Sequential), TestMethod]

Data Source Attribute XML


[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\data.xml", "Iterations", DataAccessMethod.Sequential), DeploymentItem("data.xml"), TestMethod]

Data Source Attribute Team Foundation


[DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://vlm13261329:8080/tfs/DefaultCollection;Agile", "30", DataAccessMethod.Sequential), TestMethod]

Data Source Attribute SQL


[DataSource("System.Data.SqlClient", "Data Source=.\\sqlexpress;Initial Catalog=tempdb;Integrated Security=True", "Data", DataAccessMethod.Sequential), TestMethod]

Data-Driven Tests
The data source is now available for you to use in this test method. You use TestContext.DataRow to access the current row of data from your data source. You can access each column using the following syntax: string paramVal = TestContext.DataRow["Input1"].ToString(); this.UIMap.EnterDataInfo.UITextInputText = TestContext.DataRow["Input1"].ToString();

Data-Driven Tests
CSV file: TestX.csv

Data-Driven Tests
Example:
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\TestX.csv", "TestX#csv", DataAccessMethod.Sequential), DeploymentItem("TestX.csv"), TestMethod] public void RecordedTest() { string paramVal = TestContext.DataRow["Values"].ToString(); string paramVa2 = TestContext.DataRow["Numbers"].ToString();

Questions?

You might also like