Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added snapshot testing for generated code #1753

Closed
wants to merge 2 commits into from

Conversation

TimothyMakkison
Copy link
Contributor

Created a separate file for snapshot testing the generated code.

  • Verify doesn't support .NET 462 so I'm using NET 481, let me know if this is a deal breaker.
  • I want to move the generated code tests from Refit.Tests to this project.
  • This is intended to support a possible source generator rewrite.

Copy link

codecov bot commented Jul 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.66%. Comparing base (6ebeda5) to head (4f82183).
Report is 58 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1753      +/-   ##
==========================================
- Coverage   87.73%   83.66%   -4.07%     
==========================================
  Files          33       36       +3     
  Lines        2348     2443      +95     
  Branches      294      343      +49     
==========================================
- Hits         2060     2044      -16     
- Misses        208      316     +108     
- Partials       80       83       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ChrisPulman
Copy link
Member

Net 4.7.2 is supported by Verify I would rather keep a lower end test than upper, would this be acceptable, the other option is to move the API Tests to a separate test project.
I wanted to get the API tests added and for the moment to avoid breaking changes, I have excluded net 4.6.2 from the API tests and am only checking net 6 and net 8

@TimothyMakkison
Copy link
Contributor Author

TimothyMakkison commented Jul 2, 2024

Net 4.7.2 is supported by Verify I would rather keep a lower end test than upper, would this be acceptable,

Absolutely, no idea why I didn't use this version. Its a shame as I'd prefer to test the generated code for .NET 461 as its the most different version (Iirc Unsafe.As isn't available.)

the other option is to move the API Tests to a separate test project.
I wanted to get the API tests added and for the moment to avoid breaking changes, I have excluded net 4.6.2 from the API tests and am only checking net 6 and net 8

Which API tests are you talking about, are you talking about all the tests in Refit.Tests? I wasn't aware you'd recently added tests 🤔

I'm also not sure if my generator tests are even using .NET Framework, NET 6.0, NET 8.0 when running. AFAIK refit.Tests\InterfaceStubGenerator uses VerifyCSV2.Testand ReferenceAssemblies to build the given file in the correct version (I think). I don't know how CSharpCompilation.Create chooses which version of .NET to use.

I'm tempted to close this PR and use it for testing a source generator rewrite (if I ever get round to it). Moving the tests from InterfaceStubGenerator isn't the main goal. I was planning on using this project for tests like the following:

public async Task TestRouting()
{
  // fixture adds this method into a blank refit interface file and verifies the output.
  await Fixture.VerifyMethod(
  """
  [Get("/group/{id}/users")]
  Task<List<User>> GroupList([AliasAs("id")] int groupId, [AliasAs("sort")] string sortOrder);
  """);
}

@ChrisPulman
Copy link
Member

The API test's are here -> Refit.Tests/API/
I added them recently to avoid releasing breaking changes accidentally without a relevant version bump.

Copy link

github-actions bot commented Aug 8, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants