How to use Microsoft Fakes for unit testing a web service? - web-services

I am working on a project which has 3 tier architecture:-
1. Business layer 2. Data layer 3. Service Layer
I want to unit test my Service layer.
Currently I succeeded to add a unit test to my Business layer by faking the Data Layer.
Now the issue is, I have a service layer which makes call to my Business layer, which in turn makes calls to my Data layer.
Initial test case that passed was written by adding a reference of Business layer project in my Unit test project and then creating Fakes of the Data layer.
Now what I want to do is, I want to achieve this by adding Reference of Service in the Unit test project and also using Microsoft Fakes at the same time.
Can someone please help me in understanding this? I am new to this Fakes framework.

This question is old, but hopefully it helps you, or someone in a search:
You seem (imho)to be mixing what is needed in your architecture(and/or integration testing) vs what is needed in unit testing. If you are trying to fake for unit testing, remember SUT! System Under Test should be the only component you are testing. In which case, if you are testing a component in your service layer you should fake(shim or stub) any calls external.
http://msdn.microsoft.com/en-us/library/hh549175.aspx
Gives a good example with the IStockfeed stub.
Please clarify if you are trying to integration test or unit test.

Related

Testing process in Laravel application development

I'm following TDD technique in my new Laravel project. Thus I have a set of tests which cover my controllers, model classes, services, etc. Most of these tests are HTTP tests, so I stored them in the /tests/Feature directory. Additionally I have few unit tests, which cover quite specific methods, which are not (easily) reachable from the HTTP tests.
If I understand correctly, each HTTP test is a functional tests, because it covers a lot of classes included Controller. Should I in that situation separately create unit tests for each method in my project even if it is already covered by HTTP tests? If yes, what benefit can I take from it.
Thank you in advance for explanations.
The philosophy of creating unit tests is to test a small piece of your code, for example, if you have an API, so it only returns the list of 10 recent posts then I guess it's no need to create a unit test for that and it can be covered with writing the functional or HTTP tests. But let's assume you have an endpoint that the user uses that endpoint to upgrade his account from regular type to golden type so he/she can access more posts or videos. There will be definitely a lot of things going on in that endpoint, so yeah you need to write Unit tests in addition to functional tests. Also, one more thing is that when you write functional tests you should see it from the QA perspective, I can categorize it like this
Functional/Http/Feature => [Validation Checks, Response Checks=>[The endpoint throw an error in different situations or return success if all goes well]]
Unit => [Write the test for the small functions that they get called by that endpoint Or write the test for that endpoint and mock everything so you can get what you expect]
Integration => [Write tests for the third party APIs or database persistence or caching persistence that you are using in your application]
So if you have an endpoint and you are writing tests for that endpoint and your functional tests has covered some part of that endpoint logic then I guess it's not necessary to write more unit tests for it.

Automated Unit Testing Oracle BPEL SOA projects

Is there an alternative to the Oracle SCA Unit tests provided with JDeveloper for testing SOA projects/BPEL?
The problem I have is with it is the amount of effort required to write the tests through the clunky UI and the smallest change will invalidate all tests currently built which makes them un-maintainable.
The other issue is due to the graphical interface the SOA composite must first be written before unit tests can be written meaning a test driven-development is not possible.
The final issue is the emulation functionality is incomplete with database partner links.
I use SOAP-UI to perform unit testing. I create separate test scripts with SOAP-UI which allow me to generate a number of different test case scenarios which can be targeted at individual services.
I then invoke these from a Jenkins/Hudson script to provide continuous integration testing.
In this way you can do your TDD without first creating the composite.
With your database partner links you can emulate them either with a stub composite or alternatively with SOAPUI. This depends on what your configuration is and exactly what you use the data for.

WP7 3 tier architecture unit testing

I have a WP7 application that uses a 3 tier architecture with an Azure service in the middle carrying out all DB manipulations but have run into difficulty when trying to wrote unit tests for this.
Can anybody suggest any methods on how I could test my system
Regards
Usual unit test solutions will work fine in this scenario. On the Windows Phone side, you can create a mocking service. That is, you don’t actually connect to Windows Azure, but you have an interface that is identical to the Windows Azure service interface. This interface returns some mocked data. You test against this mocked interface. On the Windows Azure side, you need to do some unit tests on data accessing layer as well as the service layer. I assume you use Entity Framework, you can create a unit test to test the CRUD operations without introducing the service. As for the service layer, you need to add a service reference in another unit test (suppose you’re using SOAP or OData), and then do the test.

Best way to write JUnit tests for SOAP service

What are the best Junit tests for soap services.
Would connecting to the web service fall under a unit test or an integration test?
I need to pick useful unit tests and was looking for ideas on tests that would be automatable and repeatable.
Thanks.
For unit tests, you should test an isolated behavior of a single class, and therefore use mocks/stubs/test doubles as much as possible. If you do not mock, then you are not testing an isolated part of your code. Hence isolating the error becomes more difficult and the test might also not be repeatable (e.g. strange network behavior might occur unrepeatably).
You should also try to automate your integration tests, where you replace your mocked objects with the real implementations.
At this infoq site you can find a short introduction about mocking web services, and several links to tutorials/tools/whitepapers.

how do you use TDD for developing webservices using Oracle Service Bus

Does anyone have any opinions on how TDD and UNIT testing would would when developing web services using Oracle Service Bus? All I can think of is stubbing out the back ends then running tests through the service bus, but that's really just integration testing. How would I apply TDD principles in this instance?
Is your question actually how best to conduct unit tests on Oracle Service Bus components? I have the same issue but have come to the view that now your unit of code is not a Java method or a class but a whole proxy.
It does however limit you to being only able, at best, to conduct component integration testing as you have described: Stubbing out the other systems and running what you'd traditionally call Integration tests through the Service Bus.
Scale up your unit of work.
If there is a better way to automate and test these code artifacts then I want to hear about it.