I'm fairly new to spring cloud. Is there a way we could perform integration test on Feign clients using test double like wire mocks or some kind of test double ? Is there a way I could get this mocked test double registered in the registry-server and then use it with FeignClient?
You can start your WireMock server on a predefined port (or register it as a Spring Bean). Then, for the sake of your tests, you can have a custom Configuration that will set the value of server list of the Ribbon Load Balancer to contain localhost:wiremockPort just like presented here - https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/WebClientTests.java#L382-L395
Related
I'm coding a REST API that connects to my Corda Node via Corda RPC. I'm trying to create a mock testing corda network with TestContainers so that I can verify the behaviors of my REST API. I know Corda has official docker image. Is there any guidance on how might I go about implementing this?
I would look at this/divide this into two parts.
Server side testing - Testing your node RPC endpoints.
Client side testing - Testing your rest endpoints.
For the first part, you can use the NodeDriver to write the integration tests. Using the NodeDriver, you can bring up nodes locally to run flows and inspect state updates. The NodeDriver allows you to access the node using RPC endpoints. You can read more about NodeDriver here.
For the second part, you can use something like mockito to mock the RPC calls and test your client logic.
This way you will easily be able to test client and server side.
To do an actual end to end integration test, you will have to start the docker nodes using a script and then you can test the methods from the client code.
I am trying to adopt Pact. I understand the consumer side of the equation and it looks very nice. But I am confused about the producer side.
It seems the documentation advocate running the provider app, and verifying the contracts against a running server.
I prefer not to do it. First, I need to curate a database with proper information for each pact, which is painful to say the least. Second, starting up the application is going to be a hassle - did I mention it is a monolith? -, finally, there are POSTS which are going to mutate the state of the database, and make test running brittle.
What I want to do is to do a mockMvc style testing with the pacts. I would like to mock my services, and just test the endpoint, which I think what should be tested in this case.
How can I achieve this with Pact?
Well if you don't test your contracts against your Provider that loses the whole point of Contract testing, since your contracts aren't tested against both sides. Because the main point is that Consumers dictate how the Provider should behave and in your case you would like to bypass the provider with a mockMvc and there is no point for doing contract testing only against your Consumer not the Provider. Even though your Provider is a monolith it's still better to run it and test with a contract, then to run all the microservices for end-to-end testing.
Yes you can achieve it with PACT, however I have the same opinion with Cotnic that it beats the purpose of having PACT on provider side. The main purpose of PACT is to verify that your server as the provider is working as according to the agreement (PACT). Therefore in my opinion the proper way to use PACT as a CONTRACT is by running it against a fully deployed server, and using #State to "Prepare" the Server (db, startup applications, etc)
Anyway, if you are using Spring, you probably can have a look at this sample for using Pact with MockMvc
https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-spring
Pact-JVM now supports Spring mockmvc tests to verify a Spring or Springboot provider. See https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-spring
Can Spring Cloud Contract be used to test Spring Boot services that are running Spring-WS Endpoints? I would like the ability to define SOAP requests/responses using the Groovy DSL, but I haven't been able to get these services to work with Spring Cloud Contract. I keep getting a failure (expected 200 but received a 404) when I try to run these tests. Interestingly, I added #RestController and #RequestMapping annotations to my Endpoint class (knowing it wouldn't work) just to test whether or not the fact that these services are Spring-WS endpoints and not Spring REST controllers may be the problem (i.e., does Spring Cloud Contract only "see" REST endpoints?). And...I moved on to a different set of errors. So, I am assuming at this point that I can not use Spring Cloud Contract to test my SOAP services, but I would like to know for sure (i.e., is there some way to do this that I haven't discovered yet?).
Our core services are implemented as REST services, but we still have to support our SOAP clients until they can migrate to REST, so they wrap our REST services. I need the ability to test both. I have successfully created tests for our REST services.
Try using the explicit mode to make rest assured send real request. In the base class you'll have to setup the whole application so that it bindd to a real port. Then in the before section of your test you need to tell rest assured that I'd should call the following port. And that's it :P
Does MOQ give access to Castle's DynamicProxy generation? Or are there configurable static methods or something in the Castle namespace that would allow me to tune MOQ's proxy gen behavior?
Some Background
I am Mocking a WCF Service endpoint (IWhatever). WCF automatically adds Async call back options for methods (e.g. IWhatever.DoWork() is also realized as IWhatever.DoWorkAsync()).
I'm looking to use the Mock<IWhatever> object while self-hosting this service mock'd; basically spoof this external web service to my system. However, when [self-hosted] WCF tries to create a DoWorkAsync() method; it already exists... which ultimately throws errors when opening the self-hosted/mock'd IWhatever endpoint. ((NOTE: I don't have access to original contract to use directly)).
Sooo.. looks like Castle DynamicProxy allows for one to define which methods should be generated (see: http://kozmic.net/2009/01/17/castle-dynamic-proxy-tutorial-part-iii-selecting-which-methods-to/). I was thinking I would use to not intercept calls on methods ending with "[...]Async". However I don't see where I would add this customization rule in the proxy generation within MOQ; hence my question.
How do I write unit tests to test the Web methods of a Web service using NUnit?
The web methods in this application will add,update and delete a record in the database.
The unit test will test a web method whether a record has been inserted in the database, the webmethod calls a method in data access layer to perform this action.
I do not think it's appropriate to be testing the end result of your web service with a unit test. Also, what you are trying to do is called an "integration test", and not a unit test.
What you can do, however, is to:
Write unit tests to check if your data access layer (DAL) is working properly
Write unit tests to see if your web method is properly accessing your DAL
You might also want to look at a question I raised before: How do I unit test persistence? to provide you more insight.
If you really are adamant to be able to do this however, it is possible to create such unit tests using MbUnit, which has the Rollback attribute.
[Rollback]
public void Test_database_persistence()
{
//any database access you perform here will be put inside a transaction
//and rolled back afterwards
}
MbUnit is totally compatible with NUnit, so you could still use tests you've already written with NUnit.