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.
- 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.
- 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.
- WebTestPlugins and PreWebTest/PostWebTest event handlers will not be called.
- WebTestRequestPlugins will not be called. Note: WebTestRequest-level events such as PreRequest, ValidateResponse, ExtractValues, and PostRequest will still work.
- CreateTransaction() and EndTransaction() will have no effect.
- 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("http://localhost/");
yield return request1;
WebTest2Coded webTest2Coded = new WebTest2Coded();
IEnumerator<WebTestRequest> webTest2Enumerator = webTest2Coded.GetRequestEnumerator();
yield return webTest2Enumerator.Current;
WebTestRequest request2 = new WebTestRequest("http://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.