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

Unable to write unit tests without adding refernece to the source generator #24

Closed
ByronMayne opened this issue Jul 28, 2024 · 0 comments · Fixed by #25
Closed

Unable to write unit tests without adding refernece to the source generator #24

ByronMayne opened this issue Jul 28, 2024 · 0 comments · Fixed by #25
Assignees
Labels
bug Something isn't working

Comments

@ByronMayne
Copy link
Owner

Description:
Unable to write unit test for source generators due to a FileNotFoundException. The exception is being thrown because the unit test project is unable to locate SourceGenerator.Foundations.Contracts.dll. The current problem is that the only way to get this reference is to add the NuGet package <PackageReference Include="SourceGenerator.Foundations" Version="2.0.4" />. The issue is then the unit tests project won't build because it's not in fact a source generator.

 AutoFactories.Tests.DiagnosticsTests.UntaggedClass
   Source: DiagnosticsTests.cs line 19
   Duration: 711 ms

  Message: 
System.IO.FileNotFoundException : Could not load file or assembly 'SourceGenerator.Foundations.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

  Stack Trace: 
AbstractTest.Compose(String source, Boolean verifyOutput, Action`1 assertDiagnostics)
AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
AbstractTest.Compose(String source, Boolean verifyOutput, Action`1 assertDiagnostics)
DiagnosticsTests.UntaggedClass() line 20
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Solution:
Create a publish just the contracts library by itself so unit tests can reference that and still compile.

@ByronMayne ByronMayne self-assigned this Jul 28, 2024
@ByronMayne ByronMayne added the bug Something isn't working label Jul 28, 2024
@ByronMayne ByronMayne linked a pull request Jul 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant