Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit test WCF method

I have created a WCF service and was trying to test one of the methods. I right clicked on the WCF service method and selected create unit test.

It created a new test project and created a unit test.

I tried to run test project but I am not sure what should be the UrlToTest value? I have put url to the service.

[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\VS Projects\\NetBranch4\\" + 
    "MobileCheckCapture\\MobileCheckCapture", "/")]
// [UrlToTest("http://localhost:45651/")]
[UrlToTest("http://localhost/mobilecc/mobilecc.svc")]
public void AuthenticateUserTest()
{
    // TODO: Initialize to an appropriate value
    MobileCC target = new MobileCC(); 

    // TODO: Initialize to an appropriate value
    string authenticateRequest = string.Empty;

    // TODO: Initialize to an appropriate value
    string expected = string.Empty; 
    string actual;
    actual = target.AuthenticateUser(authenticateRequest);
    Assert.AreEqual(expected, actual);
    Assert.Inconclusive("Verify the correctness of this test method.");
}
like image 544
user228777 Avatar asked Oct 28 '11 13:10

user228777


1 Answers

You're better off hand-rolling your own tests rather than having VS build one for you. Just new up the service as if it's a normal class inside your test and call the function, assert against the value you expect back. All of my WCF services are tested like normal classes, now actually connecting to the service and getting answers back is more of an integration tests as connecting and ensuring endpoints are correct isn't really related to testing the logic of the service.

ETA: I test the logic first because a lot of the times connection problems, firewall issues, etc. can take time to solve with WCF services, and I reserve testing that last.

like image 129
Mark W Avatar answered Sep 23 '22 01:09

Mark W