Okay, I'm sure some of you will tell me, "Yeah, I know this already!", but I've been asked this several times. So in addition to pointing you to the MSDN documentation, I thought I'd give my own example.
The more mainstream recommendation for testing a web service is to use a unit test. Code up the unit test, add a reference to the service, call the web service, and assert the results. You can then take the unit test and run it under load via a load test.
However, what if you want a more visual test? Well, you can use a web test to record interaction with a web service. This is actually documented in the MSDN Library here, but below is my simple example.
Here's what we're going to do:
First, we create a web service. In my example, it's the sample "Hello, World" service and I've created one additional method called "HelloToPerson":
As you can see, the method will simply say hello to the passed person's name.
Now, let's create a web test to exercise this web method (Test->New Test, select Web Test), creating a test project in the process if you don't already have one in your solution. I named my web test WebServiceTest.webtest.
As soon as Internet Explorer opens with the web test recorder in the left pane, click the "Stop" button in the recorder. This will return you Visual Studio's web test editor with an empty test.
Now launch Internet Explorer, go to your web service (.asmx), and select the method to test (again, in this example it's "HelloToPerson"). Examine the SOAP 1.1 message. In my example, the message looks like this:
We'll need to refer back to this information (I color-coded a couple of sections for later reference).
Right-click on the root node (WebServiceTest in my example) and select "Add Web Service Request."
In the URL property of the new request, enter the URL of the web service (by default this value is populated with http://localhost/.
Now, let's make sure we use a SOAP request. Right-click the request and select "Add Header".
Enter "SOAPAction" in the name field. In the value field, enter the value of SOAPAction in the message from your web service. For my example, it's "http://tempuri.org/HelloToPerson" (color-coded in blue)
Next, select the String Body node
Now, right-click on the web service request and select "Add URL QueryString Parameter."
In the QueryString Parameter node, specify "op" as the name and the name of your method as the value. In this example, it's "HelloToPerson".
Finally, let's run the test and see the results!
As you can see, the test passed, and the "Web Browser" panel shows the returned SOAP envelope with the correct results.
Now for some more fun. Let's make this a data-driven test so we can pass different values to the web method.
We'll create a simple data source so that we can pass several names to this method (very helpful so we don't have to record multiple tests against the same method). You can use a database, XML file, or CSV (text) file as a data source. In my example, I'm going to use an XML file:
<?xml version="1.0" encoding="utf-8" ?> <TestData> <Name>Steve</Name> <Name>Mickey</Name> <Name>Devin</Name> <Name>Joe</Name> <Name>Eric</Name> </TestData>
Save this file as "Names.xml" in your test project.
To make this data source available to the web test, right click on the web test and select "Add Data Source" (you can also click the corresponding toolbar button).
Provide a name for the data source (for me, it's "Names_DataSource") and select XML file for the data source type.
Next, provide the path to the XML file, then select the data table containing your test data. You'll know if you select it correctly since you'll get a preview of your data.
Check the boxes next to the data tables you want to be available for your tests. In my example, I only have one ("Names").
Click Finish (if you're asked to include any files in your test project, just click yes to the prompts).
Now your XML data is available to bind to your web test.
Finally, let's put this data source to work. We want to bind the name values in the data source to the "person" parameter for my web service call. If you recall, that value is specified in the String Body property. So we inject the following syntax (using the values appropriate for this example) into the String Body property:
{{DataSourceName.TableName.ColumnName}}, so for my example, I use {{Names_DataSource.Name.Name_Text}}
Now we just need to tell the web test to execute once for each value in my data source. We can do this two ways:
If you will mostly just run this test in a single pass (not iterate through the data source), you can just run your test and "Edit Run Settings" to augment (on a one-off basis) your iteration settings.
Again, note that doing this way will affect only the current test run (i.e. next run made), and will not be saved.
If you want to specify that you want to use the data source by default, you need to open the LocalTestRun.testrunconfig file in your Solution Items folder.
Opening the .testrunconfig file will give you the below dialog. Select Web Test on the left, then click the radio button to specify "One run per data source row." Click Apply then Close.
Now for the beautiful part. Go back to your web test and run it again. This time instead of a single run, it will automatically execute a test run for each row in your data source.
Notice results for each run, including pass/fail information, and the resulting SOAP envelope with the appropriate method result in each (I've highlighted the second run to show that "Mickey" was used in this run).
Happy Testing!
I downloaded this yesterday and played around a little bit with it. It's quite awesome to explore the stars in this fashion. What is it? Well, to quote the description from the website:
"The WorldWide Telescope (WWT) is a Web 2.0 visualization software environment that enables your computer to function as a virtual telescope—bringing together imagery from the best ground and space-based telescopes in the world for a seamless exploration of the universe. Choose from a growing number of guided tours of the sky by astronomers and educators from some of the most famous observatories and planetariums in the country. Feel free at any time to pause the tour, explore on your own (with multiple information sources for objects at your fingertips), and rejoin the tour where you left off. Join Harvard Astronomer Alyssa Goodman on a journey showing how dust in the Milky Way Galaxy condenses into stars and planets. Take a tour with University of Chicago Cosmologist Mike Gladders two billion years into the past to see a gravitational lens bending the light from galaxies allowing you to see billions more years into the past. WorldWide Telescope is created with the Microsoft® high performance Visual Experience Engine™ and allows seamless panning and zooming around the night sky, planets, and image environments. View the sky from multiple wavelengths: See the x-ray view of the sky and zoom into bright radiation clouds, and then crossfade into the visible light view and discover the cloud remnants of a supernova explosion from a thousand years ago. Switch to the Hydrogen Alpha view to see the distribution and illumination of massive primordial hydrogen cloud structures lit up by the high energy radiation coming from nearby stars in the Milky Way. These are just two of many different ways to reveal the hidden structures in the universe with the WorldWide Telescope. Seamlessly pan and zoom from aerial views of the Moon and selected planets, as well as see their precise positions in the sky from any location on Earth and any time in the past or future with the Microsoft Visual Experience Engine. WWT is a single rich application portal that blends terabytes of images, information, and stories from multiple sources over the Internet into a seamless, immersive, rich media experience. Kids of all ages will feel empowered to explore and understand the universe with its simple and powerful user interface. Microsoft Research is dedicating WorldWide Telescope to the memory of Jim Gray and is releasing WWT as a free resource to the astronomy and education communities with the hope that it will inspire and empower people to explore and understand the universe like never before. "
See how it works (details here), but to summarize:
Search
Search for cashback deals at Live Search cashback. Each time you click a Live Search cashback listing, you'll find great deals on the product you chose. Your results will clearly list the cashback savings you'll receive off the store price, and your final bottom-line price that includes tax and shipping costs. Also look for this icon when you search for a product on Live Search to find great cashback deals.
Shop
Compare and sort products by the bottom-line price. Click the best deal to go to the store. Everything you buy during that store visit will be eligible for Live Search cashback. On your first time using Live Search cashback, we will ask you for an email address so we can tell you how to quickly set up your free cashback account.
Save
Keep saving money each time you use Live Search cashback. Every time you make a qualifying purchase, we'll send you an email to confirm your Live Search cashback savings. When your cashback account reaches a balance of at least $5, you can claim your cold, hard cash. Terms and conditions.