Add TUnit.AspNetCore.Core that does not depend on the TUnit metapackage? #5471
|
My solution currently consists of these projects:
I added the TestHost project because I have some shared test infrastructure that is expensive to create (Postgres testcontainer with data seeding) and want to share it between Contoso.Tests and Contoso.Web.Tests using Currently, Contoso.Tests and Contoso.Web.Tests depend on TUnit.Core; Contoso.TestHost on TUnit (the metapackage). Now, I want to leverage TestWebApplicationFactory from TUnit.AspNetCore which would require Contoso.Web.Tests to depend on TUnit.AspNetCore. But TUnit.AspNetCore in turn depends on the TUnit metapackage, which would make Contoso.Web.Tests a test app itself instead of a test library. How to handle situations like this? Should I accept the dependency and e.g. configure my csproj like this (didn't check if that'd work): <IsTestProject>false</IsTestProject>
<IsTestingPlatformApplication>false</IsTestingPlatformApplication>
<IsTestingPlatformEnabled>false</IsTestingPlatformEnabled>Or should TUnit.AspNetCore actually depend on a to-be-created TUnit.AspNetCore.Core or similar that could contain the required code without depending on the TUnit metapackage? |
Replies: 3 comments 7 replies
|
Hmm yeah you're right - bit of an oversight on my part. It should probably just depend on TUnit.Core, and users bring in TUnit or TUnit.Engine themselves. Be a bit of a breaking change for me to do this if there's users only consuming the aspnet package at the moment 😭 |
|
I think its broken again with adding reference to TUnit.OpenTelemetry in .Core project |
|
We also have the same problem with the TUnit.Aspire project, that pulls in the "TUnit" package and therefore every library that only imports TUnit.Aspire is recognized as test project. This in turn also affects the TUnit.OpenTelemetry package (since it pulls in TUnit.Aspire and therefore TUnit). Solution could be the same as for the TUnit.AspNetCore project:
On the other hand, I think it would be more intuitive if the TUnit package is the only project that configures the project as "TestProject" - and all other packages would then just be "extensions". Test project configuration would then be always the same - adding TUnit + the extension projects you need (aspire, openTelemetry, mocks, ...). If the current approach of creating separate packages with the .Core extension (e.g. TUnit.Aspire.Core), then it would be very helpful to have a hint in the documentation that "shared infrastructure library projects should only depend on TUnit.x.Core, because the otherwise are recognized as test projects). |
Yeah it's a good idea - thanks! It's probably the easiest approach 😄