In our project we have an other project B dependency. I'm trying to write Integration tests for this flow.
Project B has hard coded API : https://store-platform-dev/items with some headers.
I tried using wiremock stub with proxiedFrom(https://store-platform-dev/items)
withHost(https://store-platform-dev/items)
And also proxyvia(), nothing seemed to work. Stubbing is not happening and the api call is not returning stubbed response.
How to approach this? Since it's the external project we can't even make changes to their api.
Related
What are the things I need to test in Controller Testing, Service Testing and Repository Testing
Example:
In controller testing I should test:
If the endpoint will not work in different HTTP Methods
If the endpoint can receive request
I want to ask suggestions from other devs so I can learn the other goals in testing
I already know some of the parts that needs to be tested but I wanna ask if there are parts that I don't know
I'm working on a client code that interfaces with a remote REST service but I'm not exactly sure how to go about mocking the service for my automated tests. I've seen this guide on how to test GORM REST, which I thought I could use as reference, but it looks like it requires a Grails environment to run fine. I'm pretty sure I can incorporate Spring Test into my Groovy project but there are other things I'm not clear about. In particular, I'm not sure how to make the following lines from the link work on plain Groovy project:
RestTemplate rt = Book.restBuilder.restTemplate
final MockRestServiceServer mockServer = MockRestServiceServer.createServer(rt)
In the given guide, Book is a Grails domain class. in the first line above, it refers to a restBuilder property, and I don't know where it came from. The main concern here, I guess, is getting an instance of RestTemplate which I'm not very familiar with.
To be clear, I don't have to stick with this approach. Setting up RestTemplate looks a little complicated without the Grails environment, so if there are other tools that would allow me to mock REST services more easily in a plain Groovy project, I'd be happy to consider them.
I have a Web API controller action that takes a quite complex object as an argument. It's to be passed to the webservice as JSON, of course, and is supposed to deserialize into an instance of a C# class.
I have unit tests in the business layer to convince me that JSON serialization/deserialization of the class in question works as expected.
And I have C# unit tests running against the Web API controllers, passing instances of this class into the actions, to ensure that if the controller actions have the right behavior, given the correct objects.
My problem: these objects are complicated enough that constructing improper JSON isn't going to be easy. My intent is to create some convenience functions, in Javascript, to aid in that construction, and I'd like to have unit tests to make sure that they work, and unit tests to ensure that properly-formatted JSON is deserialized into the target class as expected.
That means I need to create, in my VS2013 solution, a way to run javascript, both as self-contained unit tests, and as calls against my Web API webservice.
Any suggestions as to what tooling would work best for that?
I'd really like something that can be contained within Visual Studio, so that it can be configured as an MsBuild target. (Would make the guys who deal with the Continuous Integration configuration much happier.)
I have a maven/mule/spring development environment that I build REST services within. I also have a series of TestNG tests to validate these services. I also want the ability to alter the responses from the services, either returning specific information or throw an exception. This was I can automatically test broader behaviours of the services. I figured that mocking the services would be the best approach, but I cannot find any good information on how to mock a REST service.
Is there any material I can review on how to mock a REST web service?
--Update---
I thought I would add an example to make the problem more concrete. If I have the following setup:
testA calls serviceA, which then calls serviceB
If serviceA should return a web exception to testA if serviceB responds with an error, I would like to inject a mockedServiceB in to the system for the test where mockedServiceB always returns an error:
testA calls serviceA, which then calls mockedServiceB (which always returns an error to serviceA)
Generally speaking I would fragment my Mule configuration to have one service per fragment then load real service A fragment and a test service B fragment at test time. Test service B would use the Mule test:component to simulate good or bad returns.
I had the same problem and wrote a small lib for mocking REST services: https://github.com/mkotsur/restito.
You can give it a try.
I am implementing a Service Contract for WCF Service.
As per TDD I wrote a test case to just pass it using hardcoded values.
After that I started to put real logic into my Service implementation. The actual logic relies on 3-4 external service and database.
What should I do to my original test case that I wrote ?
If i Keep it same in order to make test pass it will have to call several other external services.
So I have question in general what should I do if I write a test case for a Business Facade first using TDD and later when I add real logic, if it involves external dependency.
Utilize a mocking framework (with dependency inversion or just a factory) so you can inject fake dependencies into the object. These can then then just return canned responses and/or be checked that the class utilizes the dependencies how you intended.
As an example, if your code calls a repository to save, we don't really care in the business method test that the repository did actually save to a persistance store, only that it got called and returned some data if required. What you're really testing is how your code reacts to what the dependency returned, or if it was utilzed correctly - but not the dependency's actual functionality
Ideally the first test should have been representative of how the class/method will work and return data, so the test would still be valid once you're finished.