I hit a snag towards the end of last week writing a series of data driven web tests using VSTS. I had decided to use SQL Express to allow me to store the test data in an MDF file in the test project. I recorded a new web test that executed perfectly. I then added the datasource to the webtest and bound the credentials to the appropriate feilds from the datasource. I then added a validation rule and bound the “Find Text” field to the field in the datasource containing the text I wanted to check was on the page. I ran the web test again and everything went exactly as expected.
Then the trouble started. I wanted to bind the “Pass If Text Found” property of the validation rule to a field in the datasource. The properties window only allows you to select True/False meaning you can’t type in the databinding syntax required to read the property value from the datasource. At this point I figured it was time to use the “Generate Code” button on the toolbar to convert the WebTest into code. This happened nice and easily but when I attempted to run the new “code” version of the web test, I received the following error;
“Could not run web test ‘ProfileControlTestCoded2’ on agent ‘vstsclnt’: Could not create instance of class ‘ProfileControlTestCoded2’ :Exception has been thrown by the target of an invocation. “
This proved to be quite an annoying error that initially I wondered if it was related to my choice of SQL Express for the datasource. There isn’t much documentation around that mentions using SQL Express for your test data.
Anyway, after posting this to the MSDN Forums, Josh Christie (MS) came to the rescue and pointed out this was a code generation bug and that the fix is to simply move the user credentials out of the constructor and into the start of the Run method. Here’s a screenshot showing the fix.