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

Run tests only for test projects #1745

Merged
merged 2 commits into from
Aug 22, 2018
Merged

Conversation

smadala
Copy link
Contributor

@smadala smadala commented Aug 22, 2018

Description

  • Avoid obvious failure for non test projects

Related issue

#1129
#705
#411

@smadala
Copy link
Contributor Author

smadala commented Aug 22, 2018

/cc @dasMulli Thanks for idea 👍 #411 (comment)

@dasMulli
Copy link

dasMulli commented Aug 22, 2018

Btw I was protoyping a different idea where:

each project exhibits a target to collect test assemblies.

<Project>
  <Target Name="CollectBuildTestOutput"
    Condition="'$(TargetFramework)' != '' or '$(TargetPath)' != ''"
    DependsOnTargets="Build"
    Returns="@(TestAssembly)">
    <ItemGroup>
      <TestAssembly Include="$([System.IO.Path]::GetFullPath($(TargetPath)))" TargetFrameworkMoniker="$(TargetFrameworkMoniker)" />
    </ItemGroup>
  </Target>
  
  <Target Name="CollectInnerBuildTestOutput"
    Condition="'$(TargetFramework)' == '' and '$(TargetFrameworks)' != ''">
    <ItemGroup>
      <_InnerTestFramework Include="$(TargetFrameworks)" />
    </ItemGroup>
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="CollectBuildTestOutput" Properties="TargetFramework=%(_InnerTestFramework.Identity)">
      <Output TaskParameter="TargetOutputs" ItemName="TestAssembly" />
    </MSBuild>
  </Target>

  <Target Name="CollectTestBuildOutput"
     Condition="'$(IsTestProject)' == 'true'"
     DependsOnTargets="CollectBuildTestOutput;CollectInnerBuildTestOutput"
     Returns="@(TestAssembly)" />
</Project>

then the solution collects the assemblies and calls dotnet vstest (since the VSTest task only accepts a single assembly but this could be done using solution extensions targets that make an updated task available)

  <Target Name="VSTest">
    <MSBuild Projects="@(ProjectReference)" Targets="CollectTestBuildOutput">
      <Output TaskParameter="TargetOutputs" ItemName="TestAssembly" />
    </MSBuild>
    <Exec Command="dotnet vstest --Framework:%(TestAssembly.TargetFrameworkMoniker) @(TestAssembly,' ')"
    StandardOutputImportance="high" />
  </Target>

@dasMulli
Copy link

dasMulli commented Aug 22, 2018

(updated to fix it for multi-targeting projects)

I have no idea how this behaves with multiple test runners or different runners in the same solution (or different versions of xunit etc.).
I guess there is some logic to handle this in the VS "run all" experience already?
But currently this works quite well when run using dotnet msbuild -restore -t:VSTest and all test projects using the same version of xunit.

@dasMulli
Copy link

(sry for spamming)

I'm fine with however this is resolved to make typing dotnet test work.
I see it as a dev experience and my tests are usually factored well enough to not have weird dependency issues.
Some users however prefer having a single trx output. (but I don't mind since VSTS can merge multiple results anyway.. need this for JS + .NET tests anyway)

@smadala
Copy link
Contributor Author

smadala commented Aug 22, 2018

I have no idea how this behaves with multiple test runners or different runners in the same solution (or different versions of xunit etc.)

Different test frameworks(NUnit, xUnit, MSTest V2,etc..) and version will be handled by vstest.console.

@smadala
Copy link
Contributor Author

smadala commented Aug 22, 2018

I'm planning to address below problems in next few days. I will create an issue for each task very soon.

image

@smadala
Copy link
Contributor Author

smadala commented Aug 22, 2018

<Target Name="CollectBuildTestOutput"
    Condition="'$(TargetFramework)' != '' or '$(TargetPath)' != ''"
    DependsOnTargets="Build"
    Returns="@(TestAssembly)">
    <ItemGroup>
      <TestAssembly Include="$([System.IO.Path]::GetFullPath($(TargetPath)))" TargetFrameworkMoniker="$(TargetFrameworkMoniker)" />
    </ItemGroup>
  </Target>

I'm just wondering can we avoid build (DependsOnTargets="Build") every time?

@dasMulli
Copy link

I think there's a NoBuild property already, so DependsOnTargets="Build" => DependsOnTargets="BuildForTestIfNecessary".
plus a BuildForTestIfNecessary target that conditions a depends on or a CallTarget on Build based on the property passed in.

Alternatively: Build the solution form the outer VSTest target and then remove the DependsOnTargets completely. The TargetPath property should be available regardless.
This will build non-test projects as well but is probably what users would expect.

@smadala smadala merged commit a2b4196 into microsoft:master Aug 22, 2018
@smadala smadala deleted the dotnet-test-sln branch August 22, 2018 10:25
@dasMulli
Copy link

@smadala contact me if you want any feedback, testing etc. (twitter, mail)

@smadala
Copy link
Contributor Author

smadala commented Aug 22, 2018

@dasMulli Sure 😄

@gitfool
Copy link

gitfool commented Sep 2, 2018

@smadala when and how will this be available? Ideally it’s in the next drop of the 2.1.x SDK. Failing that, the next 2.2.x SDK preview. Finally, more out of curiosity, is there a way to drop in a nightly build of just MS Build Core?

smadala added a commit to smadala/vstest that referenced this pull request Oct 5, 2018
@smadala smadala mentioned this pull request Oct 5, 2018
smadala added a commit that referenced this pull request Oct 8, 2018
* Verify NS.JSon is loaded appropriately in case of DisableAppDomain (#1740)

* reverting back app domain culture setup

* binding redirect for TW.Interfaces

* Run net451 test for Newtonsoft dependency

(cherry picked from commit 3cbab0b)

* Run tests only for test projects (#1745)


(cherry picked from commit a2b4196)

* Upgrading the version of VSSDK Build tools nuget, because the older one is incompatible with the latest VSSDK. (#1761)


(cherry picked from commit d391224)

* Added linkes to all RFCs (#1743)

Added links to all RFCs to address #1392.

* refined link test to .NET Core CC RFC.

* Update README.md

(cherry picked from commit 4d89670)

* Get latest extensions from VS d15.9stg branch (#1771)


(cherry picked from commit d5c4415)

* Add info log if try to run tests with no IsTestProject prop (#1778)

* Add info log if try to run tests with no IsTestProject prop

* Add message to resources

* invert check

(cherry picked from commit 3decca0)
GeoK added a commit to AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet that referenced this pull request Nov 20, 2018
GeoK added a commit to AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet that referenced this pull request Dec 3, 2018
GeoK added a commit to AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet that referenced this pull request Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants