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

Make NUnit tests runnable in VS Test Explorer #455

Merged
merged 3 commits into from
Jul 29, 2019

Conversation

stakx
Copy link
Member

@stakx stakx commented Jul 26, 2019

While the test projects can simply be started to run the tests (thanks to NUnitLite), tests cannot be run in VS Test Explorer, which could be handy especially when one wants to run only a subset of all tests.
Currently, doing that requires one to set a --test=... command-line argument in the test project settings.)

This commit adds the packages required to run our tests in VS Test Explorer.

@stakx stakx changed the title Make NUnit tests runnable in VS Test Explorer WIP: Make NUnit tests runnable in VS Test Explorer Jul 26, 2019
@stakx
Copy link
Member Author

stakx commented Jul 26, 2019

Agh! I had everything working fine, then updated Visual Studio to 16.2.0, and now tests once again no longer run. I'll investigate. It'll likely be due to this test run error (there are a few of those):

An exception occurred while invoking executor 'executor://nunit3testexecutor/': Incorrect format for TestCaseFilter Error: Invalid Condition 'FullyQualifiedName=Castle.DynamicProxy.Tests.CustomAttributeInfoTestCase.FromExpression_Creates_Same_CustomAttributeInfo_As_Calling_The_Constructor => new MyAttribute1 {IntProperty = 42, StringProperty = "foo", ArrayProperty = new [] {1, 2, 3}},Castle.DynamicProxy.CustomAttributeInfo'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.

@stakx
Copy link
Member Author

stakx commented Jul 26, 2019

Found the problem, reported it on Microsoft Developer Community, and added a workaround to prevent test run failure.

I know we're uglifying a unit test here (hopefully only for the time being), however I think it's worth the price if it allows us to pick and run tests straight from Visual Studio.

@stakx stakx force-pushed the vs-test-explorer-support branch from e673376 to 7ad2287 Compare July 26, 2019 13:02
@stakx stakx changed the title WIP: Make NUnit tests runnable in VS Test Explorer Make NUnit tests runnable in VS Test Explorer Jul 26, 2019
@@ -38,8 +39,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting to see Microsoft.NET.Test.Sdk is versioned 16.2.0. Is this a package just for Visual Studio with a name making it sound like it is for all .NET CLI unit testing.

Copy link
Member Author

@stakx stakx Jul 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, the package version isn't directly tied to a particular version of VS. But I have never been too clear what exactly requires this package... maybe VS, maybe VSTest. I might run some experiments to find out. Will report back my findings if & when I do so.

Copy link
Member Author

@stakx stakx Jul 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonorossi, while I don't understand the whole theory behind that package, it indeed enables dotnet test! In fact, we can use all of dotnet restore|build|test now, if we make one further addition in common.props that looks roughly like the following (as per dotnet/msbuild#1333 (comment)):

<PropertyGroup>
  <FrameworkPathOverride Condition="'$(TargetFramework)|$(OS)' == 'net35|Windows_NT'">$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
  <FrameworkPathOverride Condition="'$(TargetFramework)|$(OS)' == 'net35|Unix'">$(MONO_DIR)/../lib/mono/2.0-api</FrameworkPathOverride>
</PropertyGroup>

(We already do something similar in build.sh for .NET 4.6.1 compilation on Mono.)

I've only verified dotnet tooling for Windows, the Mono/Linux override will need some more work. But essentially, the MONO_DIR variable can be set on the shell using export MONO_DIR=$(dirname $(which mono)), then passed in to the MSBuild projects.

@jonorossi
Copy link
Member

I know we're uglifying a unit test here (hopefully only for the time being), however I think it's worth the price if it allows us to pick and run tests straight from Visual Studio.

Agreed. I was expecting something much uglier 😉.

stakx added 3 commits July 29, 2019 16:43
While the test projects can simply be started to run the tests (thanks
to NUnitLite), tests cannot be run in VS Test Explorer, which could be
handy especially when one wants to run only a subset of all tests.
Currently, doing that requires one to set a `--test=...` command-line
argument in the test project settings.)

This commit adds the packages required to run our tests in VS Test
Explorer.
@stakx stakx force-pushed the vs-test-explorer-support branch from 7ad2287 to fa6486b Compare July 29, 2019 15:03
@stakx stakx merged commit 7de1dc1 into castleproject:master Jul 29, 2019
@stakx stakx deleted the vs-test-explorer-support branch July 29, 2019 15:57
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.

2 participants