Using WireMock in integration tests does not pick up the SerializerSettings defined in the StartUp
See original GitHub issueIn the Startup:
.AddNewtonsoftJson(x => x.SerializerSettings.NullValueHandling = NullValueHandling.Ignore)
The integration test custom WebApplicationFactory (which is then used with the Startup of course):
public class IntegrationTestWebApiFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
const string url = "http://localhost:60007";
builder.ConfigureTestServices(
services =>
{
// other stuff
services.AddSingleton(_ => WireMockServer.Start(url)); // hoped it would pick up the json settings... nope!
});
The issue is then that the WireMockServer does not pick up the json settings (null ignore) set in the startup (I see null fields in the wireMockServer.MappingModels, whereas my API does not serialize nulls, as expected from startup settings)
I’ve found a way around it but I would like to know if it’s possible for WireMockServer to pick up the json settings defined in startup
I did this just after the const string url line:
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
// settings must be aligned on the settings defined in startup. Annoying! Is there a better way?
NullValueHandling = NullValueHandling.Ignore
};
Issue Analytics
- State:
- Created a year ago
- Comments:9
Top Results From Across the Web
WireMock not intercepting http request with Spring boot ...
Within your test you are now calling the real port of your launched spring boot app for your test through return "http://localhost:" +...
Read more >How to Use WireMock for Integration Testing
As an HTTP mock server that can map specific requests, stub them, and, like a proxy, return predefined responses according to your test...
Read more >Using WireMock.net for Integration Testing
In this tutorial, we are going to be looking at using WireMock.net to mock API calls in our integration tests. If you already...
Read more >Spring Boot Integration Tests With WireMock and JUnit 5
This article showcases a testing recipe for writing integration tests for Spring Boot applications using WireMock and JUnit.
Read more >Using WireMock for integration tests in Spring apps
In this article, we'll discuss Wiremock, a tool you can use to simulate other services on which your app depends during a unit/integration...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Oh, I meant please do as you suggested:
Pls also update the doc as I suggested.
Was caught with things, so did not take the time to follow up, but you did 👍 Thank you very much. I’ll try the new nuget as soon as released.