Why are my MSpec specifications not recognized by ReSharper? - unit-testing

I know how to integrate MSpec with R#, I'm aware of "blocked DLLs" problem. But I still can't figure out why my tests are not recognized. I'm integrating MSpec in an unusual way though. I do not use NuGet. I have old MSpec build - 0.4.9 - which my tests are built for. I manually create Plugins folder for R# and put the following DLLs there:
Machine.Specifications.dll 0.4.9
Machine.Specifications.ReSharperRunner.6.1.dll 0.5.0 (built from GitHub sources)
After I start VS and open R#'s options dialog the runner is displayed in the Plugins section. But my tests are not recognized. Can the version mismatch be an issue? Does R# have any logging where I can see its communication with the plugin?

Did you try to download the 0.4.9 binaries from NuGet and use the ReSharper runner from this release? The current source doesn't support these old versions anymore.

I have finally sorted that out. I had to debug the runner as described here - https://github.com/machine/machine.specifications/blob/master/debugging-resharper.txt. And I found out that the runner was built for ReSharper 6.1.37.86, which is not the latest 6.1 release, list is here - http://resharper-support.jetbrains.com/entries/21206508-Where-can-I-download-an-old-previous-ReSharper-version-. The latest 6.1 release is 6.1.1000.82 which is installed on my machine. So the runner just could not find required ReSharper assemblies during startup. I fixed the problem by adding assembly redirects into devenv's config file. The redirects are needed for all ReSharper files the runner depends upon, there are 16 of them in total. Example redirect is:
<dependentAssembly>
<assemblyIdentity name="JetBrains.Platform.ReSharper.ComponentModel" publicKeyToken="1010a0d8d6380325" culture="neutral"/>
<bindingRedirect oldVersion="6.1.37.86" newVersion="6.1.1000.82"/>
</dependentAssembly>

For anyone coming at this problem with a Visual Studio 2019 / Resharper 2019.3.4+ setup, what worked is using Resharper's inbuilt extensions manager.
In VS, go to:
Extensions -> ReSharper -> Extension Manager
and search/install "Machine.Specifications for ReSharper"

Related

Guidance for running tests using MSTest v1 in Visual Studio 2017 15.8.1

I upgraded to Visual Studio 2017 last week. A solution with several test projects using MSTest v1 seemed to be fine at first. Most test projects execute tests fine. This is .NET Framework, not .NET Core.
However, there is one project where I am encountering issues. It's an integration test project, meaning it runs web application tests using the ChromeDriver and Selenium. This project references NUnit, though that reference comes from another project reference. I am not actually using NUnit as my test framework.
This is the error when trying to run any test in that particular test project:
Could not find test executor with URI 'executor://mstestadapter/v1'. Make sure that the test executor is installed and supports .net runtime version .
Test project {name} does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project.
It's recommended to reference NuGet test adapters in each test project in the solution.
Disabling the option indicated below made everything work:
I found this solution after browsing the preview release notes at https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-preview-relnotes#--visual-studio-2017-version-158-preview-4 (scroll down to "... What's New ..." and then .NET Test Adapter Extension). It mentions this breaking change (though it didn't break my other projects), but there is no mention of what to actually do to solve the problem.
Of course, long-term, keeping that option unchecked doesn't seem feasible. So I am looking for guidance on how to proceed.
I already tried to see if I could "quickly" upgrade to MSTest v2, but that had an issue because System.Runtime 4.1.2 couldn't be found. I tried adding System.Runtime 4.3.0 via NuGet, but that didn't solve the issue.
I was getting a similar issue running Xamarin.UITests and resolved it by installing the "NUnit 2 Test Adapter" Extension in Visual Studio. In Visual Studio 2017 you do this from Tools > > Extensions and Updates... > Online > Search "NUnit Adapter" > click the NUnit 2 Test Adapter then the Download button to install. Restart Visual Studio when prompted to complete the installation.
It would be interesting to understand how the MSTest V1 framework assembly(Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll) is referenced in this project. The compatibility checkbox that also ended up being disabled in the image above should ensure that this project has MSTestV1 tests and enabled run tests. If it isn't then for some reason the detection logic is busted and needs to be fixed - a snippet on how the assembly is referenced would be helpful there.
As for moving to MSTest V2, this blog should help: https://blogs.msdn.microsoft.com/devops/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/ . And for the specific issue you seem to be running into, this github issue on the repo sounds similar: https://github.com/Microsoft/testfx/issues/184 .
Caltor's answer pretty much solved it for me: it was the NUnit Adapter I needed. But I followed slightly different steps. Here they are for VS 2019 (but probably apply to VS 17 too):
Right clicked on the References node under my project in the solution explorer
Chose "Manager NuGet packages"
Clicked Browse
Searched for nunit3testadapter
Hit install on the result that popped up
The issue for me was similar to the OP's - the adapter was installed on some projects but not others. But confusingly this wasn't immediately visible under the "References" node for that project. The only node relating to nunit under that References node said "nunit.framework". So the references for test with and without the adapter looked the same.
"... but that had an issue because System.Runtime 4.1.2 couldn't be found."
I think this is a setting in the app.config that does not get updated when the project settings are updated. I searched for System.Runtime under the packages folder and then changed my app.config to match what I found, and then that particular problem went away.

NUnit3 throws exception System.Runtime, Version=4.2.0.0 not found while trying to run test in NUnit3 console

Environment:
.Net Core 2.0
visual Studio Professional 2017
NUnit3
OpenCover (For code coverage)
ReportGenerator(For code coverage report)
Hi Nunit Team,
I am pretty familiar with MS Test framework and have worked on that extensively but was testing how suitable NUnit framework would be and so wanted to do a small POC around that. I created a small classlibrary and a unit test project. Below are the NuGet package been installed:
NUnit 3.7.1
But when I try to run the test cases from console runner like below I get exception saying System.Runtime, Version=4.2.0.0 assembly not found.
C:\Users\UN\.nuget\packages\nunit.consolerunner\3.8.0\tools>nunit3-console.exe D:\Code_Trials\BoMLibrary\BomTest\bin\Debug\netcoreapp2.0\BomTest.dll
Exception detail:
Errors, Failures and Warnings
Invalid : D:\Code_Trials\BoMLibrary\BomTest\bin\Debug\netcoreapp2.0\BomTest.dll
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
----> Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Run Settings
DisposeRunners: True
WorkDirectory: C:\Users\Smukherjee.nuget\packages\nunit.consolerunner\3.8.0\tools
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETCoreApp,Version=v2.0
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 4
Am really not sure why so? No matter what I try not able to pass through this error. Moreover, when I try to install the assembly from Nuget I don't even find a assembly with version 4.2.0.0.
Tried installing the version 4.3.0.0 of System.Runtime but no luck. Can you please help on this.
Strange thing, I have got a sample unit test project (as part of opencover nuget install) which targets .Net Framework 4.5 and have NUnit2.6.7 package installed and when I try to run that using NUnit3 console it works like charm.
Even, installing NUnit3 latest stable version 3.10.1.0 doesn't help either. Also, it's surely not an Opencover issue since opencover console just passes the test run request to NUnit console. So the issue has to be around NUnit.
Let me know if you need more information around this.
Found the answer to this here https://github.com/nunit/nunit/issues/2763
NUnit Console doesn't run .NET Core tests - you need to use dotnet test instead. Take a look at this page:
https://github.com/nunit/docs/wiki/.NET-Core-and-.NET-Standard

build dotnet solution in travis against netstandard20 and framework462

TLDR; I've got a mixed solution: NetStandard 2.0 for the library I'm actually developing and .Net Framework 4.6.2 (or alternatively dotnetcore 2.0) for the tests. How to configure travis.yml to build the library and the test project as well.
I'm actually working on a client for a rest api. I decided to use .NET Standard 2.0 as project type. As it is a REST based api, I decided to use Newtonsoft.Json to deserialize and serialize the content.
A problem occurred: the nuget package Newtonsoft.Json 10.0.3 doesn't support NetStandard 2.0 by now. But I found the commit ab3315f does. So I cloned the repo and build the netstandard library on my own as a workaraound till the new version is available in NuGet.
I added the project to CI system travis following this post: https://rimdev.io/building-net-core-on-travis-ci/
Now I added a test project to my solution using Nunit to run unit tests and integration tests for my library. No I'm facing 2 problems and I need to solve one:
problem 1: When my test project targets .NET Framework, I'm able to execute all the unit tests without any problems, but now travis complains based on my travis.yml there's no mono installed to build the complete solution correctly.
my question here: how to change my .travis.yml to build both project types within the solution.
problem 2: When my test project targets dotnetcore, my local build works, but when I try to execute tests locally, I get a runtime error:
System.IO.FileNotFoundException : Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null'.
That's why I didn't test travis build by now, as I want to get it running locally first if this is the solution. I don't know why it doesn't find the dependency.
Any suggestions either for problem 1 or for problem 2?
I ended up adding NuGet package of Newtonsoft.Json 10.0.3 to my dotnetcore test project though it is not directly used there. Now the runtime error diappeared. So I am able to test locally and remotely as well and let travis CI build my project.

Run ReSharper plugin tests using R# test runner

I'm building a R# plugin and decided to cover it with tests. However, I noticed, that plugin tests cannot be run using the R# runner if plugin target version is the same as R# version.
For instance, if you try to run tests using JetBrains.ReSharper.SDK.Tests of version 2016.2.20160818.171542, you'll get the following error:
ERROR System.TypeLoadException:
Method 'RunTests' in type 'JetBrains.ReSharper.UnitTestRunner.nUnit26.BuiltInNUnitRunner' from assembly 'JetBrains.ReSharper.UnitTestRunner.nUnit26, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
In previous versions the error was different.
Likely, that happens because R# runner and SDK assemblies make a mix.
Is there any way to configure project/R# to be able to run plugin unit tests using the R# runner? Likely, R# dev team uses their own runner.
Thanks!
Unfortunately, this is a bug in the ReSharper runner in 201.6.2. Something to do with having multiple copies of the same assemblies in the same process - the assemblies from the install, and the assemblies from the bin folder. Something's getting messed up along the way.
You can subscribe to, vote and track this issue: RSRP-460399
The workaround is to install an older version of ReSharper into a Visual Studio "experimental instance" aka "custom hive", and use this instance to develop and test the plugin. The normal instance can be used for other day-to-day development.
You can download an older version of ReSharper here (e.g. 2016.1.2), and in the installer, click Options and enter the name of a custom instance, e.g. "Plugins". Then create a new shortcut to Visual Studio and set the command line to "devenv.exe /rootSuffix Plugins" (or whatever you called the custom hive).
R# and SDK must be either of different major versions, or of binary compatible versions. Unfortunately, within EAP the internal APIs inside the test runner have changed, so R# and SDK from different EAPs are not compatible.

How to debug unit test with MonoDevelop?

I have MonoDevelop 2.4.2 on OSX. I have a failing unit test that I would like to debug. Is there a way to do it? I found a reference on MonoDevelop mailing list but my version does not have mentioned option.
Am I missing something?
I was able to debug a unit test library by right-clicking my "unit test project" in the "Solution Explorer" and choosing "Debug Item".
I'm running the Windows version of MonoDevelop, but the same option is available on Linux and OSX versions.
On OSX monodevelop 3.0.4 this is now: Right click on unit test -> run with -> "Mono soft debugger".
You can add breakpoints using the 'run' menu too, if you need to.
I am running Xamarin Studio Community. #Kedde's answer does not work for the NUnit test in this version of the IDE. I created a Console project that runs unit tests. I am able to debug by stepping into the console methods.