question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using WireMock in integration tests does not pick up the SerializerSettings defined in the StartUp

See original GitHub issue

In 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:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
FredCnicommented, Aug 2, 2022

Oh, I meant please do as you suggested:

… I update the settings to include a new setting JsonSerializerSettings which you can override as you like.

Pls also update the doc as I suggested.

0reactions
FredCnicommented, Aug 24, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found