Question

I have an application that sends messages to an external web service. I build and deploy this application using MSBuild and Cruisecontrol.NET. As CCNET build and deploys the app it also runs a set of test using NUnit. I'd now like to test the web service communication as well.

My idea is that as part of the build process a web service should be generated (based on the external web services WSDL) and deployed to the build servers local web server. All the web service should do is to receive the message and place it on the file system so I then can check it using ordinary NUnit for example. This would also make development easier as new developers would only have to run the build script and be up and running (not have to spend time to set up a connection to the third party service).

Are there any existing utilities out there that easily mock a web service based on a WSDL? Anyone done something similar using MSBuild?

Are there other ways of testing this scenario?

Was it helpful?

Solution

I just started looking into http://www.soapui.org/ and it seems like it will work nicely for testing web services.

Also, maybe look at adding an abstraction layer in your web service, each service call would directly call a testable method (outside of the web scope)? I just did this with a bigger project I'm working on, and it's testability is working nicely.

OTHER TIPS

In general, a very good way to test things like this is to use mock objects.

At work, we use the product TypeMock to test things like Web Service communication and other outside dependencies. It costs money, so for that reason it may not be suitable for your needs, but I think it's a fantastic product. I can tell you from personal experience that it integrates very well with NUnit and CCNet.

It's got a really simple syntax where you basically say "when this method/property is called, I want you to return this value instead." It's great for testing things like network failures, files not being present, and of course, web services.

Take a look at NMock2. It's a open-source mocking product and allows you to create "virtual" implementations for interfaces that support rich and deep interaction.

For example, if your WS interface is called IService and has a Data GetData() method, you can create a mock that requires the method to be called once and returns a new Data object:

var testService = mockery.NewMock<IService>();
Expect
    .Once
    .On(testService)
    .Method("GetService")
    .WithNoArguments()
    .Will(
        Return.Value(new Data());

At the end of the test, call mockery.VerifyAllExpectationsHaveBeenMet() to assure that the GetData method was actually called.

P.S.: don't confuse the "NMock2" project with the "NMock RC2", which is also called "nmock2" on sourceforge. NMock2-the-project seems to have superseded NMock.

This might also be something - MockingBird. Look useful.

At my work place we are using Typemock and nUnit for our unit testing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top