Testing a remote WebService module in Visual Studio 2010

I need to change my unit test from local to remote tests, and so far I thought that all I need to do is change UrlToTest to point to another server ... But VS continues to insist on creating a development web server instead using the one that is already running.

So, after reading some documents, my question really is that I am installing Test Controller and Test Agent on a remote and local computer, or what? What to do if WebService is on Linux ...

Please note that I do not want to debug the application that I am testing. I just want the tests to run for an already running WebService that has been deployed.

I should probably mention that all my tests consist of WebService calls and some checks:

[TestMethod()] [HostType("ASP.NET")] [AspNetDevelopmentServerHost("MainProjectName", "/")] [UrlToTest("http://servername:port/websitename/TestingOnlyWebForm.aspx")] public void LoginEmptyDataTest() { IUserService userService = CreateIUserService(); string email = ""; string password = ""; ReturnMessage<User> actual; actual = userService.Login(email, password); Assert.AreNotEqual(true, actual.Status); Assert.AreNotEqual("db_error", actual.Info); } 

But I also have more complex tests in which I change some data and send it to another WebService, etc.

Please note that UrlToTest previously pointed out to localhost at what point it is running, but it starts the developer server, which is not what I want.

+4
source share
4 answers

What you are trying is impossible. All that the unit test is trying to do is run the test locally on the computer, either using the development server, specifying AspNetDevelopmentServerHost, or using local IIS when there is no AspNetDevelopmentServerHost.

If you want to test remote services, click on the unit test project and add a link to the service. Point to your service, give it a namespace, say, Services, and create a proxy. Once you have created the proxies, just create them and call the methods. Also remove all unnecessary attributes from your test. Your test should look something like this:

  [TestMethod] public void LoginEmptyDataTest() { using (var userServiceClient = new Services.UserServiceClient( "BasicHttpBinding_IUserService", "http://someremotehost/userservice.svc")) { var result = userServiceClient.Login("user", "password"); // asserts go here } } 

This may solve your immediate problem, however you should consider what you are doing as @eglasius said. What happens if the code you invoke changes state inside? The next test may fail because of this, so you need cleaning strategies, otherwise your tests will be very fragile and you will eventually ignore them.

Refresh : passing the address at runtime. Change the first parameter to any enpoint configuration name that you have in your configuration file.

+3
source

I will take a hit in the dark on this because recently I did something similar.

In my case, my test project referred to a service project to ensure the visibility of service contracts and the data that the Web service implements and consumes.

To solve this problem, although it can be ignored, move the contracts to a new project. Then ask the services and test projects to link to the new project and remove the link to the test projects for the service.

Hope this makes sense!

After removing the link, VS will no longer feel the need to start your service when running the tests.

0
source

You can disable the start of the service node in the project settings of your WCF service project. Right-click - WCF Settings - Uncheck "Run WCF Service Host when debugging another project in the same solution."

0
source

You really need to consider the nature of what you are trying to achieve here.

It's hard to say for sure that you click on the code. I got the impression that you have a website that calls a web service. You are testing client code in this context, and not just checking the service.

If this happens, remove the attributes and provide the URL to the correct service, for example UrbaEsc. If you do not remove the attributes, you run the calling code in the context of the site.

Even if the above is not a script and based on the fact that you answered UrbanEsc in the comments, you will then test the external call to the web service initiated from the same site process.

You said: "Found, but VS is still running something on the local host and then trying to reach the external server ... It seems that VS is just not designed for real remote testing of web services"

Read above. I would say you need to better understand what you are allowing. Of course, you can test remote web services, for example, you can do almost anything you can encode. You do this from client code that does not know anything else that any other external service client would know. Support does not stop there, since you can perform load testing of the service.

Please note that what you are doing is not unit tests, these are integration tests. Or depending on the size of your system, complete system tests.

0
source

All Articles