I created a unit test to test if a I can login to my ASP.NET web service. The web service works fine and even the login process.
However when trying to connect to it through my test it is giving me an error:
The URL specified (‘http://www.foo.com/’) does not correspond to
a valid directory. Tests configured to run in ASP.NET in IIS require a
valid directory to exist for the URL.
I’m running my web service through visual studio, since the project is still in development.
this is my test code:
[TestMethod()]
[HostType("ASP.NET")]
[UrlToTest("http://www.foo.com/")]
public void Login_Test_It_Fails_If_GUID_IS_Wrong()
{
//Arrange
Service service = new Service();
string pGUID = string.Empty;
string connectionSQL = @"XXXXXXXXXX";
bool targetOutput = false;
//Act
targetOutput = service.Login(pGUID, connectionSQL);
//Assert
Assert.IsFalse(targetOutput);
}
Thanks in advance.
You’re doing an integration test here, as you are testing that your application can communicate with an external dependency.
If you wanted to unit test, you might want to explore a different approach.
If the web service is something you control, you can write tests for the service itself confirming its login authentication logic.
For your consuming application, you can write unit tests based off of a mock of the service to ensure that your application exhibits the correct behavior when it receives a response from the service.
On another note, passing the connection string to use into the service seems like a poor design. Why should the calling application need to have any knowledge of what database the service should be using?