2
votes

This is the weirdest thing. I have a solution with multiple Class Library projects (all .Net Framework 4.7) and multiple unit test projects to test those class libraries. Once in a while I upgrade my NuGet packages to keep them up to date, and some of those upgrades introduces an app.config file to the test-project. Once that app.config is introduced, the tests are not longer discovered by Visual Studio, and therefor they are no longer ran after each build. Considering a failed test is a trigger to correct code, this created a scenario where we would introduce code that failed the unit tests, but because we relied so much on automation, we assumed it succeeded.

In summary: - the existence of an app.config makes VS2017 not discover the tests in the project containing the app.config, even if the app.config is completely empty. Only deleting the config-file will make VS2017 rediscover the tests - Everything in the solution is targeting .Net Framework 4.7 - All Nuget Packages are updated, including the MsTest Adapter and TestFramework - The app.config files are filled only with assemblybinding entries, forinstance:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
1
Are you using Resharper by any chance? If so, what version? (An older version of Resharper could cause unit tests to not be discovered, but it was fixed some months ago.)Matthew Watson
I have had a problem with Sophos Anti-Virus preventing VS2017 unit tests from being discovered, so I suggest seeing if switching off your AV helps.Polyfun
No ReSharper here, Matthew.Jeroen
Thanks for that tip, Polyfun, but it didn't help.Jeroen

1 Answers

2
votes

Found the perpetrator, thought I'd share in case anyone else runs into this. After adding the System.Runtime NuGet package to my test-projects, the tests got discovered by VS2017.