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

Libraries referencing a test project will fail when running dotnet test #4945

Open
Youssef1313 opened this issue Feb 9, 2025 · 2 comments
Open

Comments

@Youssef1313
Copy link
Member

Youssef1313 commented Feb 9, 2025

Describe the bug

When running tests with VSTest, dotnet test is not going to fail if a project doesn't have IsTestProject set to true. This is because of the target having a condition on IsTestProject:

https://github.com/microsoft/vstest/blob/4b7642501171db13c4a942fbf5dbe443dffd0fd7/src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets#L44

For MTP, if the library is setting TestingPlatformDotnetTestSupport (which is common because we want to advise users to set it in Directory.Build.props), then we will attempt to run the library as a project.

We should consider adding IsTestProject condition to InvokeTestingPlatform target.

Alternatively, we could add <TestingPlatformDotnetTestSupport Condition="'$(IsTestProject)' != 'true'">false</TestingPlatformDotnetTestSupport> after this line:

<TestingPlatformDotnetTestSupport Condition=" '$(TestingPlatformDotnetTestSupport)' == '' ">False</TestingPlatformDotnetTestSupport>

Steps To Reproduce

Run dotnet test on the attached solution.

TestProject32.zip

Note: It works with VSTest.

Note 2: It's not a good practice that a library is referencing a test project and is usually a sign of a bad design of some sort.

Expected behavior

Actual behavior

Additional context

@Youssef1313
Copy link
Member Author

@Evangelink I'm classifying as a bug as I think TestingPlatformDotnetTestSupport shouldn't have an impact on non-test projects

@Youssef1313
Copy link
Member Author

As we discussed offline, IsTestProject is not the right thing to do as it's VSTest property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant