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.

Integration test does not serialise my request

See original GitHub issue

I can’t pinpoint why my integration test is not working; it seems somewhere the request object doesn’t get serialised into my Endpoint method.

I hope you can give me some clues where to find the issue.

I am using a middleware just to see whether the json object is posted. That is the case. But in the end the HandleAsync(Request req, CancellationToken ct) req object stays empty.

I am using XUNIT.

Using this class definition public class EndpointFixture : WebApplicationFactory<Program> to get my unit testing to work.

The unit test class itself public class EndpointTests : IClassFixture<EndpointFixture>

	[Fact]
	public void LoginForUnknownUser()
	{
		var client = _fixture.GetAnonymousClient("en");
		var (_, result) = client
			.POSTAsync<Endpoint, Request, Response>(
				new Request
				{
					Email = "unknown@user.com"
				}).GetAwaiter().GetResult();

	// leaving out my assertions here
	}

the GetAnonymousClient is coming from the EndpointFixture class

public HttpClient GetAnonymousClient(string language)
	{
		var client = Server.CreateClient();
		client.DefaultRequestHeaders.Add("X-Request", "XXXXXXX");
		client.DefaultRequestHeaders.Add("X-Language", language);
		return client;
	}

As said, when I place break points, my Endpoint is called OK (so the client basically is working, and using my discovered endpoints)

By my request object - the properties of it - are all null while I know 100% sure (my debugging my Middleware) that I get the correct json with the Email field filled-in.

Can you point me in a direction / hook where I can see when the request object is filled so I can debug through it?

Debug print of the response body: image

Same call, outside the unit test: image

where my request is filled in.

public class Request
{
	public string Email { get; set; }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
dj-nitehawkcommented, Mar 13, 2022

v3.11.0-beta3 released

0reactions
dj-nitehawkcommented, Mar 13, 2022

yeah making the change now… will push out next beta in a few minutes! this check was an old relic from some past code which is no longer necessary…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integration test does not serialise my request · Issue #61
I am using a middleware just to see whether the json object is posted. That is the case. But in the end the...
Read more >
spring-data-rest integration test fails with simple json request
spring-data-rest integration test fails with simple json request · I am just wondering where is the association declared in Person class. It ...
Read more >
Testing Serialization With Spring Boot @JsonTest
It's possible to test the deserialization of requests and serialization of responses using @WebMvcTest . We can use MockMvc to test the ......
Read more >
Does the test fixture have an option/feature to ...
My question is: is there a way to pass a serializer to the fixture and have it attempt to serialize/deserialize each command and...
Read more >
Stop testing your (de)serializers | by Luís Soares | CodeX
Let's now consider a way to test (de)serializers in the context of their owner adapter. Being an indirect way, the test coverage remains...
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