Share via


Can I call a web test from a web test?

I've seen this question come up several times recently, so I'm going to try to provide the full answer here.  Let me start by saying that we have some significant changes in the pipeline that will make calling a web test from another web test a fully supported feature in a future release.  Until then, I do not recommend it due to the gotchas listed below.

  1. The web test engine will not load data sources in the called web test.  A possible workaround is to use custom databinding such as reading values directly from a database using ADO.NET.
  2. The WebTestContexts in the caller and callee web tests are not unified.  This can make it difficult to share values between the tests such as the current username or session ID.  This can also make it very difficult to use extraction rules since the rules will extract values into the caller's WebTestContext, but the callee will try to read the values out of its own WebTestContext.
  3. WebTestPlugins and PreWebTest/PostWebTest event handlers will not be called.
  4. WebTestRequestPlugins will not be called.  Note: WebTestRequest-level events such as PreRequest, ValidateResponse, ExtractValues, and PostRequest will still work.
  5. CreateTransaction() and EndTransaction() will have no effect.
  6. MoveDataTableCursor() will have no effect.

That's quite a list of gotchas, but calling a web test from another web test can still be done if you're not depending on databinding, transactions, the context, or plugins.

If you still want to call a web test from a web test, the code should look like this:

public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest request1 = new WebTestRequest("https://localhost/");
yield return request1;

    WebTest2Coded webTest2Coded = new WebTest2Coded();
IEnumerator<WebTestRequest> webTest2Enumerator = webTest2Coded.GetRequestEnumerator();
while (webTest2Enumerator.MoveNext())
{
yield return webTest2Enumerator.Current;
}

    WebTestRequest request2 = new WebTestRequest("https://localhost/");
yield return request2;
}

Again, I do not recommend calling web tests from other web tests in VS 2005.  It would be best to wait for the next release when it will be a fully supported feature.

Comments

  • Anonymous
    July 12, 2006
    Thomas Murphy on Team Data CTP4 Project System - Not Backward Compatible.

    Josh Christie on Can I call...

  • Anonymous
    December 19, 2007
    Visual Studio Team System for Testers Content Index for Web Tests and Load Tests Getting Started Online

  • Anonymous
    December 19, 2007
    Visual Studio Team System for Testers Content Index for Web Tests and Load Tests Getting Started Online