質問

I have a WCF application in VS2012. We have also added a testing project for doing unit tests. This is all working well

In addition to this, I need to add another test project for doing system tests, the idea here is that the web service would start, and the test project would fire Http Requests, as kind of an end to end test of the service in the environment it is in.

I am not sure if there is actually a way of doing this using the built in visual studio tests. If I add a normal test class, the website that runs the web service doesn't get started, and the test fails.

The code I am trying to run is like:

[TestMethod]
public void CreateLogin()
{
    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri("http://localhost:61886/");          
    HttpResponseMessage response =          
       client.GetAsync("ssoauthenticationservice/createssologin").Result;
}

I feel like I am missing something very obvious here. So my questions are:

1) Can I test my web service in this manner - is there some way that I can set the project properties so the web service starts first, then the test project runs

or:
2) Is this approach completely wrong, and what I should really be doing is putting my tests into an executable that I can just run in whatever environment we deploy to as a quick post-deployment smoke test.

役に立ちましたか?

解決

You can most definitely test your wcf service using this method. Whether or not its good depends on your point of view. it also depends on whether or not your business implementation is tightly coupled with the .svc code behind.

To do this, you will most likely need to create a service host in a TestInitialize or ClassInitialize and tear it down after your test are run.

You can see more about self hosting here http://msdn.microsoft.com/en-us/library/ms731758.aspx

Should also note that how well this method works is dependent on the environment that the unit test is run. It works great from a local machine, but requires admin permissions. Because of this, using this method seems to be a bad idea in a continuous integration environment.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top