How do I use multiple rows per test?

Suppose I have a test that performs the following:

1) Log in

2) create an order

3) add 3 items to the order

4) checkout

5) logout

I created my test and did the data binding and when I run it, I get the same order three times, always the first row in the database. I would like to be able to be able to get a new record each time I add an item to the order.

What am I doing wrong

Thanks



Answer this question

How do I use multiple rows per test?

  • AaronJ

    That's unfortunate. I was hoping to keep from writing much code for my tests. Other options I've thought of are:

    1) using one text file for each of the 3 items. Each file would have, say 10 rows, and I could set each item insert to pull from it's own data file. Then I would set the test up so that it ran once for each row in my data source.

    2) generating code from my web test and mucking with that to get multiple data source reads.

    Option 1 isn't attractive because requires quite a bit of data manipulation to run the test multiple times. This is only the case because one of the item-specific fields is a guid that cannot be re-used.

    Options 2 and 3 aren't attractive since writing code that needs to be maintained is not where I was hoping to go.

    David, Thanks for the suggestion, I'll have to think about where I want to go from here.


  • AndreaMaria

    Ack. I upgraded my test environment and bad things happened...I'll need to fix those issues before I can get back to this.

    I am running everything locally, so there shouldn't be anythign to deploy, right Anyway, I've got other things to fix before I can get back to the task at hand.


  • Michael Pryhodko

    Another option is to continue to use a declarative web test, but just implement the code for a "Web test request plug-in". From the web test request plug-in code you can access the WebTest object which as a method called MoveDataTableCursor() that allows you to advance the cursor in the data source to the next row.

    See the online docs on How to Create a Web Test Request Plug-in at: http://msdn2.microsoft.com/en-us/library/ms182554(VS.80).aspx.

    Your Web test request plug-in would look something like this:

    public class MyWebTestRequestPlugin : WebTestRequestPlugin
    {
    public override void PostRequest(object sender, PostRequestEventArgs e)
    {

    // Check request URL here; otherwise you'll get a new row for all requests
    if (e.Request.Url.EndsWith("AddOrderItem.aspx")
    {
    e.WebTest.MoveDataTableCursor("MyDataSourceName", "MyTableName");
    }

    }
    public override void PreRequest(object sender, PreRequestEventArgs e)
    {
    // You could move the code from the PostRequest handler to the PreRequest handler if you want to advance to a new row before the request
    }
    }


  • TekRichy

    Hello,

    I think that what you're looking for is a data-driven unit test. With these kind of tests, data will be retrieved from row(s) of a data source, and this data will be availabe from some properties in the TestContext class.

    Please take a look at the following links for more info on how to actually accomplish this:
    http://msdn2.microsoft.com/en-us/library/ms182527.aspx

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnvs05/html/vstsunittesting.asp

    Thanks,
    David Gorena Elizondo
    [MSFT] VSTS


  • MikeBC

    After you run the test, check the "Test Results" window. If the test fails with the error you indicated, there could be a link to click in the yellow status bar of the "Test Results" window. It will be labled with something like "Tests failed". Click this link to view the test run result (note this is different than the web test result which is contained in the list box).

    If there was an error deploying the assembly to the agent machine it should be listed in the run report. It sounds like the assembly may not be getting deployed to the agent.

    Thanks,
    Rick


  • chr.dev

    You can set a breakpoint in the plugin code and then run the web test using "Debug Test" instead of "Run Test" from the web test editor. If you don't hit the breakpoint then the plug-in isn't being called (which we can try to investigate if that's the case). Otherwise, you can trace through the plug-in and see if you're taking the expected code path.

    Check the context tab in the web test result viewer to see if the data bound value is changing after each call to the PostRequest plugin (it should be called something like datasource1.table1.column).

    Does this help
    Thanks,
    Rick


  • Ronald Wilson

    Thanks for the additional suggestion! I added this plugin successfully (maybe). I can see the plugin in the properties of my web test. But I don't see any change in behavior. My Context tab in the test results still show the same data for each call.

    I verified the DataSource and Table name as well as the request url. I added a couple items from the sample in the link you provided, but overall it seems to attempt to do the right thing.

    Any thoughts

    Thanks for all your help.

    using System;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.WebTesting;
    
    namespace RequestPluginNamespace
    {
      /// 
      /// Increment Cursor in Database after each read.
      /// 
      public class IncrementItemRowPlugin : WebTestRequestPlugin
      {
        public override void PostRequest(object sender, PostRequestEventArgs e)
        {
    
          // Check request URL here; otherwise you'll get a new row for all requests
          if (e.Request.Url.EndsWith("ItemProxy.asmx"))
          {
            e.WebTest.MoveDataTableCursor("DataSource1", "ItemSoapBySection");
          }
    
        }
        public override void PreRequest(object sender, PreRequestEventArgs e)
        {
          // You could move the code from the PostRequest handler to the PreRequest 
    handler if you want to advance to a new row before the request
        }
      }
    }
    


  • Old Mortality

    It looks like the request plugin wasn't being invoked even though I had it listed in the 'Request Plug-In' property for the web test.

    I'm getting an error now saying "Could not run web test 'CreateOrder' on agent 'not-bob'; Could not create instance of class 'IncrementItemRowPlugin' : Could not load type 'RequestPluginNamespace.IncrementItemRowPlugin' from assembly 'CreateOrder'."

    I've just gotten the error and haven't spent the time to verify everything is set up properly, but wanted to let Rick know I'm working on his suggestion.

    Thanks Rick.


  • How do I use multiple rows per test?