mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
WireMock not working in Debug within test project #295
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @xadvfh on GitHub (Sep 30, 2020).
Describe the bug
When you place a breakpoint and try to make a call to the mock server via an external tool (browser), there is no response. This was first seen in #122
It would be nice if this worked since you could easily check if the json response bodies you're creating are working as expected. Right now I have to add a long
Thread.Sleep()to check my work.Expected behavior:
Server should be listening in debug mode.
Test to reproduce
Other related info
I'm using dotnet core 3.1 and nunit 3.
@StefH commented on GitHub (Sep 30, 2020):
Please provide a full working example.
@xadvfh commented on GitHub (Sep 30, 2020):
Thank you for the fast response, here is a full working example:
@StefH commented on GitHub (Sep 30, 2020):
@xadvfh
Some things which could maybe help you:
[OneTimeSetUp]instead of[SetUp]My own development environment has some issues now, so I cannot reproduce your issue right now. I'll come back to you.
@xadvfh commented on GitHub (Sep 30, 2020):
[OneTimeSetup]is only executed once before ALL tests are run. If we want a new server instance for each test we would have to use[Setup].I'll try with xunit later today and see if that helps.
@StefH commented on GitHub (Oct 1, 2020):
@xadvfh In the
[Setup]you can use theserver.Reset()method to reset all mappings before each test.@xadvfh commented on GitHub (Oct 1, 2020):
@StefH how would that work in running tests in parallel. Resetting would delete all mappings for other tests currently running, no?
@StefH commented on GitHub (Oct 1, 2020):
I'm not 100% sure for NUnit, but I think that all tests within a single .cs file are run sequentially.
At least I'm 100% sure that XUnit does it like this.
@xadvfh commented on GitHub (Oct 1, 2020):
So I just tested with the latest version of xunit and it has the same problem. I even removed any setup related stuff and am creating the server in the test itself. Working example:
@StefH commented on GitHub (Oct 1, 2020):
My NUnit test class:
However when debugging, I get this message to allow access:

And debugging via menu:

Works fine:

@xadvfh commented on GitHub (Oct 1, 2020):
Were you able to make a request from a browser/postman while stopped at a breakpoint after the stubbing(line 24)?
@StefH commented on GitHub (Oct 1, 2020):
No, this is not possible. UnitTesting with WireMock needs to be done completely in the unit-test like this:
Screenshot:

@xadvfh commented on GitHub (Oct 1, 2020):
I understand. My usecase is that we're creating complex json object and during the creation phase it would be nice to be able to see what we're creating in a more readable manner. Is there a technical limitation why setting the breakpoint doesn't work but adding a long sleep works fine?
@StefH commented on GitHub (Oct 1, 2020):
The debugger probably stops several threads, so also the code which listens and responses to requests.
About complex json, is this the response message?
@xadvfh commented on GitHub (Oct 1, 2020):
Is there a way you recommend setting up the wiremock server so we can do debugging? for example, if you create an asp.net core API you're able to debug.
Yes. we're mocking an API that is used by a UI. We have models set up but there are nested objects. On top of that, we have created builders to allow test writers to create responses dynamically based on what they need.
@StefH commented on GitHub (Oct 2, 2020):
If you just want to verify if the JSON is correct, then the easiest solution is to created your complex nested objects and serialize these to a json-stirng yourself.
And then provide this json-string to the code:
server.Given(Request.Create().WithPath("/test")).RespondWith(Response.Create().WithBody(json_string));@xadvfh commented on GitHub (Oct 2, 2020):
do you have an idea of where in the codebase this issue could be happening? maybe I can do some digging and see if we can fix this.
@xadvfh commented on GitHub (Nov 2, 2020):
@StefH just checking in to see if there is anything I can help with to fix this. Is there a place in the code you would recommend to start troubleshooting?
@StefH commented on GitHub (Nov 2, 2020):
Maybe change the async behavior from the GetAsync?
@StefH commented on GitHub (Feb 4, 2021):
@xadvfh Do you still have an issue? Or can this one be closed?
@xadvfh commented on GitHub (Feb 4, 2021):
@StefH I still have this issue.
@xadvfh commented on GitHub (Feb 10, 2021):
@StefH I tried this again yesterday to wanted to confirm this issue still exists.
My use case is that I am using WireMock.Net to replace API calls that are made by our website. At times i want to place a breakpoint to pause the test and click around in the website. However, anything that triggers a call to wiremock will not respond while i am in a breakpoint.
@StefH commented on GitHub (Feb 20, 2022):
Hello @xadvfh,
Did you try the latest version yet?
@StefH commented on GitHub (Feb 27, 2022):
@xadvfh : can you please check the latest version ?