views:

280

answers:

3

Say I have created a webservice and WCF service.

How are the different kinds of testing (viz. unit testing, SIT, etc) performed for web services and WCF service.

Do i need to explicitly create a sample project to test the service by passing input parameters and analyzing output parameters or are there any tools through which we can perform all kinds of testing.

+2  A: 

There are different kinds of testing like you said.

I like unittesting. To unit test your webservice, you would create a seperate project, and create a testclass that has a bunch of testmethods. In each of those methods you yould test your DLL (NOT The Webservice hosted by IIS/whatever) and verify it behaves as expected.

You should also make sure that the DLL is not comunication to anything on the outside during a UNIT-Test (That means: Filesystem, Database, other webservices, anything you dont control). Reason for that is that you want to test YOUR code, and not possible infrastructure issues like network, authorization, or state of the database...

There are testrunners in VS or you can download testdriven.Net or resharper.

See: http://en.wikipedia.org/wiki/Unit%5Ftesting

Then there are also integration tests. Those would basically test the webservice when it is hosted by IIS, and make sure that the setup as a whole works smoothly. An integration test supplements a unittest, but should not be the only test. I would go as far and say "Integration tests are late tests", and fixing bugs dicovered during integration usually costs more then fixing those dicovered during unit tests.

Heiko Hatzfeld
+1 mention of integration testing. It's one thing to test as a unit, but if it's part of a deployment package, there really should be a few automated tests to verify the service is available.
bryanbcook
+3  A: 

Since WCF services are just classes, they can generally be unit tested like any other class, provided you don't use any WCF-specific functionality in your service class. You can start with Mark Seemann's blog post about this.

For more end-to-end style integration testing, there are a variety of considerations to keep in mind:

  • Deployment/topology: Is the service hosted at a remote external endpoint, outside of the test client? Or does the test environment need to install and host the service locally? The answers to these and related questions will determine how to design the setup portion of the testing.
  • Client types: Do the clients of your service communicate over specific transports (HTTP, TCP, etc.)? Do they require message-level or transport security? Do they use transactions, asynchronous communication, large and small message sizes, etc.? The answers to these questions will determine how large your possible "test matrix" might be.
  • Server configuration: Does your service support multiple platforms or hosting types? Do you have any "knobs" on your service that could be modified in production? Ideally these will be tested so you know that you don't have any hidden bugs.
  • Validation: How do you know that your service has done the right thing? Do you need to inspect server-side logs for errors/warnings? Are you concerned with performance or memory characteristics for various operations (if so, you may want performance counter readings)? How much validation can be done solely from the client perspective?

This is just a small sampling of the kinds of things that go into testing a web service. It is a hard problem that requires the right level of expertise and a good degree of teamwork. Your test engineers should work closely with the developers/architects to understand how the service works and how it will be used in production. This will help them create a plan with the right scope and coverage for the intended use cases.

To address the other part of the question: there are some libraries that can automatically generate simple tests with input/output values. The Microsoft Research project "Pex" is one such example.

bobbymcr
PEX is usefull for integration tests, that are written once the code is done already. Pex will also honor "code contracts" and include those in its evaluation. Interesting project
Heiko Hatzfeld
+1 for Pex. It's a neat concept that combines unit-testing with code profiling to find alternative inputs that you should test for.
bryanbcook
A: 

In addition to the Unit Testing approaches, you might also want to look into WCFStorm for testing WCF and web services. It takes a black box approach to testing services. With it, you'll be able to create test cases and dynamicaly invoke the service.