4

I'm designing an enterprise level web app that will have a Data layer + SQL database, a WCF REST web service layer that communicates with the data layer, then an MVC website which will communicate to the WCF REST web services. I want to have automatic unit testing at each level of the design.

I have created a data layer unit test project fine, which tests the EF models, repositories, operations etc and have about 15 tests I can click a button for and run which so far, tests all the functionality the data layer provides.

I want to have the same at the WCF service layer but I cannot figure out how to have an automatic test project to run against a WCF service. I've seen articles on using WCF test client to load the service in the background and be able to input parameters to each service method and see results, but I don't want a manual process, I want it to be automated, to mock the data layer and test the service calls in isolation. Complicated by the fact that ideally I would like to test the RESTful side of it, so being able to simulate GET/POST/PUT/DELETE etc and also to call certain methods with the wrong method and to confirm it fails as expected and so forth.

Is there a good solution to do this automatically or am I approaching this wrong?

1
  • Possible duplicate of WCF Unit Test Commented Feb 14, 2016 at 3:32

3 Answers 3

3

You sure can create tests that can automatically run to test WCF services.

See SO discussion here:WCF Unit Test

However one question you need to ask in your test strategy / test case design is that howmuch of the REST endpoint testing need to be unit tests and how much need to be part of system/ integration test. Because the wcf endpoints (including REST) will allow you to treat the system as a black box and do system tests without having any intimate knowledge of the internal types.

Sign up to request clarification or add additional context in comments.

Comments

1

I wrote an article on how to do that. You have to abstract the business logic to a service which either calls the real service or a mocked one. http://gaui.is/how-to-mock-and-test-wcf-services-using-moq/

Comments

-1

you can change the address of the service to localhost. this way you can start the service and test it with no mocking

1 Comment

It is a bad idea, because service(local or remote) can do some changes on remote database, or connect to some other service/ESB etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.