-2

I am trying to load test a webservice endpoint. I had a data driven unit test built for testing it. My data source is a CSV file and the unit test picks it up and runs smoothly. But when I hook the test to Microsoft Visual Studio LoadTestFramework it is not able to pull the data from CSV file.

My unit test is the one like below:

[TestMethod]
[DeploymentItem("MyProject\\testdata.csv")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV","|DataDirectory|\\MyProject\\testdata.csv", "iq3#csv", DataAccessMethod.Sequential)]
 public void DataDrivenWebApiTest()
 {
     var username  = (string)Context.DataRow["Username"];
     var password = (string)Context.DataRow["Password"];
     var token = GetToken(username, password);
     var task = RequestClient.GetRequest("/api/endpoint", ApiUrl, token);
     var result = task.Result;
     result.EnsureSuccessStatusCode();
  }

The above unit test is running good in isolation but when hooked to Visual studio load test framework it throws NullPointerException at line 6 i.e "(string)Context.DataRow["Username"];" it says object reference set to null. Can someone please help

somu27
  • 1
  • 5
  • What happens when the load test runs? What error messages are produced? The phrase *" it is not able to pull the data from CSV file"* tells us nothing. Please [edit] the question to add the details we need to understand the problem. – AdrianHHH May 18 '16 at 08:37
  • 1
    Have you solved this problem? If not then please [edit] the question after reading [mcve]. If you have solved the problem then please read http://stackoverflow.com/help/accepted-answer . – AdrianHHH Jun 10 '16 at 11:33
  • Please add an answer to the question, if you found one. – Naresh Apr 30 '18 at 10:19

1 Answers1

0

I have never seen data extracted using the ... = (string)Context.DataRow[...]; style of your code. All the examples I have seen and used use the style ... = Context.DataRow[...].ToString();.

As your code fails on the line extracting data it would seem that a file is being deployed and opened successfully. How do you know it is the correct file? Might a different file have been deployed? Look in the TestResults directory for the test run and in its subdirectories. Check that the CSV file has the correct contents. Other common reason for the error you show is that the file contains an empty (i.e. blank) line, or that the field is empty.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87