简体   繁体   中英

Problems Running AutoFixture xUnit Theory After Upgrading Project to NuGet 3.0

I have encountered a problem with AutoFixture and have submitted a GitHub issue for it . However, doing some searching on here there appears to be a few questions that are similar to my issue (but do not solve it) so I wanted to ask on here for greater visibility.

The problem is this: I recently upgraded my NuGet 2.0 projects (packages.config) to NuGet 3.0 (project.json -- NOT to be confused with ASP/.NET Core's project.json). Everything made the jump except for a particular set of tests:

Those tests that utilize and are decorated with AutoFixture's AutoData (or InlineAutoData ) theories.

I have created a very simple reproduction of this issue and that can be found here: https://github.com/Mike-EEE/Stash/tree/master/ReSharper.NuGet30

(Please note the name reflects an initial impression that the problem was ReSharper related, but it indeed affects both it and the native VS unit test runner.)

You can try to build the solution and should find that it builds OK, but tests are found neither in ReSharper's test runner nor the native VS test runner (please note I am running VS 2015 Update 3).

However, commenting out these lines and rebuilding should successfully discover all tests as expected.

This is a headscratcher and is a blocker for me to continue. Is there a consideration I am overlooking? FWIW, I have cleared out my %TEMP%\\VisualStudioTestExplorerExtensions as suggested in the xUnit documentation and it has not worked, either.

Any assistance would be greatly appreciated!

tl;dr

You need to manually add an assembly binding redirect for xUnit in the configuration file:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="xunit.core"
                                  publicKeyToken="8d05b1bb7a6fdb6c"
                                  culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-2.1.0.3179"
                                 newVersion="2.1.0.3179" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

This way both ReSharper and Visual Studio Test Explorer are going to pick up the tests that use the AutoFixture.Xunit2 glue library.

Background

The problem you're seeing has to do with the new transitive package restore mechanism introduced in NuGet 3.0.

When using the project.json format, the install/uninstall scripts bundled within a package are no longer run . This is because transitive package restore does not modify any files on disk .

From the documentation :

Install/Uninstall scripts

These scripts are not supported and will be ignored. In case they exist in the package a project using transitive restore.

The main reason we removed support for this is that in the transitive model, is that there is no concept of package install time. A package is either present or not present, but there is no consistent process that occurs when a package is installed.

One important job of these install scripts was to add all the necessary assembly binding redirects to the project's configuration file, since NuGet doesn't do it automatically, as we discovered a few years ago .

Now, with transitive package restore, the install script is no longer run, so you have to manually add the binding redirects yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM