Im writting unit test for a WCF service which i have written. The thing is when i run the Unit test it throw me error saying that there is no end point listening. I need to compile my WCF Service and later run the unit test.
Is there any other way where Unit Test runs and host the WCF service and later start testing.
Thanks in advance
Running a test against an actual WCF service would not be unit testing, it would be integration testing; if you want to do this you'd do it as part of an automated build process which deploys the service and then runs your tests.
To unit test your service, you should ignore the WCF aspect and call the service class directly, as if it were any other class.
Related
I have got the Mule 4 application which is driven by Scheduler to schedule every 30 minutes. I have added http listener under the file test-listener.xml just for invoking it for building the integration testing.
I want the test-listener.xml to be deployed only into non-production environment. How can I achieve it in Mule 4.3.0 Runtime
Thanks
Adding an HTTP Listener to test the flow is not a good practice. If you are interested on just testing the flow just use MUnit to implement tests of the flow. If you are interested on testing the scheduler execution you can use this method with MUnit: https://docs.mulesoft.com/munit/2.3/test-flow-with-scheduler-cookbook
I have REST web service which needs to be tested. I am using Mockito for mocking DAO classes and RestAssured for testing REST methods through URI. Is there any way to test REST service without running it separately with Tomcat? Or how to run application on Tomcat with mocked classes before test cases?
There is a tutorial that shows you how to use maven to start an embedded instance of tomcat and run tests against your service using RestAssured:
http://www.hascode.com/2011/09/rest-assured-vs-jersey-test-framework-testing-your-restful-web-services/
You start tomcat in one shell and run your tests in another.
However, I strongly recommend using the jersey test framework which transparently spins up an embedded container. In this case you wouldn't use RestAssured at all, but the jersey test client. Your tests will run more quickly and with less fuss. It's well documented here: https://jersey.github.io/documentation/latest/test-framework.html. The tutorial also demonstrates this approach, though it doesn't seem to me that the client is correctly constructed.
In the past I've also tested REST resources by calling the implementing class methods directly. Though this doesn't test the correct mapping of the http query parameters/body to java method parameters, it was often sufficient (especially when I'm also coding the client side code).
Just wanted to know whether we can have a Unit Test Project dedicated to a WCF Solution or not ? I know this might be a Generic question but I couldn't get specific answer to it even though I searched through various blogs and websites. Please suggest.
yes its possible to unit test WCF services. The options are:
create classes which do all of the work which are separate from the WCF service. Unit test these classes in isolation. Make your service a thin wrapper which calls these classes.
test directly with the WCF service class without it being hosted (a bit like this example)
Have the unit tests host the WCF service in process and then call the services via named pipes or similar (see the console example here for details of how to self-host). When you self host you should start the service in the test setup or the test fixture setup and then destroy it in the corresponding teardown.
I want to load test an application having its own WCF service using Visual Studio 2012. I tried creating a web performance test and use it with load test but, web performance is not recording the intermediate request send to service which is very much required.
Using CodedUI with it not feasible since it does not put on that much load and and its interactive.
The application is on different server and service too.
Any suggestion to accomplish this in VS2012.
Use dedicated "Unit Tests" for this. VS Load Tests can execute Coded UI/Web Performance or Unit Test.
In your Unit Tests, simply use a standard WCF proxy, channelfactory or RestClient.
Just check that you dispose well a Web Service Proxy class
I am working on some WCF services and they will be deployed to Azure, so I would like to try to accomplish as many unit tests as I can locally, in order to avoid useless roundtrips to the staging area while we run the integration tests.
The services use the CQRS pattern and I have layered everything in the following way:
- A bootstrapper to inject dependency into the WCF services
- A command for each service method
- A command handler to intercept the commands
So far I can fully unit test the commands, the handlers and the bootstrapper. What I still need to write is this type of test:
[TestMethod]
public void Client_ReceiveValidCommand_WillExecute()
{
var factory = new ChannelFactory<IDomainWriteService>("*");
var service = factory.CreateChannel();
var expectedCommand = BuildAddUsersCommand();
service.AddUsers(expectedCommand);
}
The problem is that this test pretends a valid endpoint in the configuration file.
Is there any way that I can start something like IIS express while my test fitness starts and then plug the channel factory into this instance of IIS?
I simply can't create a staging area where I can deploy my services and run my integration tests so I would prefer to follow the unit test way where possible.
I found an interesting article here: http://www.reimers.dk/jacob-reimers-blog/testing-your-web-application-with-iis-express-and-unit-tests which explains how to host your test in IIS express and of course run IIS express within your unit tests.
In this way I can simply create on fly a new instance of IIS express and host my WCF service, run the unit tests and finally destroy everything.