ReSharper Unit Test Runner: Support for Deployment Items - unit-testing

I like the Unit test runner in ReSharper 4.5, and would like to use it with my MSTest tests, but one thing annoys me:
In some of our solutions, we have set up some Deployment Items in the .testrunconfig file. The ReSharper Unit Test runner does not seem to respect this, so I get errors when trying to run the unit tests from ReSharper.
Is there any workraound for this ?
Update:
citizenmatt's answer was correct, the option to use a .testrunconfig with ReSharper exists in the Options dialog of ReSharper. You have to select the unit test provider on the list, then the controls to do that appears. (That was not obvious or discoverable, at least not for me ;-)

Have you had a look in the Unit Testing options page? There's a setting there to allow you to use a specified test run configuration, or a test run configuration specified in a metadata file. I'm not sure what it means - I've never used it - but it sounds like it might help.

Why not use Post-Build event of your test project? Put all your deployable items in a .BAT (.cmd) file and call it in Post-Build event to get everything deployed.

Related

Kotlin multiplatform projects run common module test in IDEA

I am using kotlin multiplatform project with js/jvm subprojects.
I used to have unit tests in jvm subproject (annotated using kotlin test annotations) and I easily ran tests using rightclick + Run 'xxx' test using junit. That option is not possible once I move those tests to common module instead.
I can still run tests using command line gradle and I even managed to create working Run configuration that worked, but I am missing that simple "right click to run" on class or even specific test method for convenience.
Is there any way to achieve that in project?
Thanks!
Which Kotlin version do you use? There was a bug with test gutters in 1.2.60, but it is fixed in the very next release which is expected to be at the beginning of the next week.
It actually should work as you described, so if it's not the version with the bug, then it's better to submit it.

DotCover fails unit test that pass in Resharper

Hi fellow programmers!
I'm trying to do some test coverage using DotCover 2.7 combined with Resharper 7.1.3. I have approximately 1300 tests in four different test projects in my solution, all of which pass when run with resharper. However, if i try to cover these tests using DotCover, one of the projects fails 201 tests that normally pass.
The error is that it tries to load some files from the wrong path, when run through DotCover. I have disabled all sorts of deployment, but resharper still outputs some testfiles to the folder C:\project\Src\TestResults, but these are removed once the tests have completed. When run through dotcover the following path generates the error:
C:\project\Src\project.Test4\bin\Debug\Deploy_abc 2014-07-01 13_26_56\Out\Configuration\Configuration.xml
The file it trying to find is located this folder:
C:\project\Src\project.Test4\bin\Debug\Configuration\Configuration.xml
So it seems that DotCover does not adopt the settings from resharper, or that there is some setting in the project.Test4.csproj-file which specifies this path. I have been through the csproj-file but didn't find anything, which is why i now turn to you guys.
As a bonus i can inform you that DotCover pass the tests if i run them individually, which only confuses me further.
Please advice!
Have you tried to specify path to .testsettings file? On the 'MsTest' page, click 'Use this Test Run Configuration', and then choose a .testsettings file (dotCover | Options).

Windows 8 App in Visual Studio 2012 - NUnit Test Adapter sees unit tests but does not run them

I have a Windows 8 Store App with two projects within the solution - one project exclusively for tests. I have added NUnit and NUnit Test Adapter (https://www.nuget.org/packages/NUnitTestAdapter/1.0.0) for this through nuget.
My tests are detected - but I cannot run or debug them. Looking at the test output window, I get the following error:
Could not find test executor with URI 'executor://nunittestexecutor/'. Make sure that the test executor is installed and supports .net runtime version 4.0.30319.34003.
I am not using resharper and I am using Visual Studio Professional 2012 Update 3 on Windows 8.1. References for the test project are as follows:
Based on my comments above, below is a workaround. Unfortunately at this stage, Windows 8.1 store Unit Test project types, using NUnit extension wouldn't work due to the different .NET targets. I tried with different Test Unit Adapters including an NUnitTestAdapterWithFramework.
It seems that the issue you haveing was occurring with standard .NET libraries targeting NUnit test adapter but the above NUnitTestAdapterWithFramework must have fixed those issue. See the Q & A section of the NUnitTestExtension
But unfortunatly it seems that this still of an issue that hasn't been fixed for Win8 Store App type Unit Testing. Pretty sure xUnit.NET also not compatible yet with different .NET target types (i,e WinRT)
So what are the options?
a. For your group, you can change them to use MSTest framework. Outcome - Problem Solved no issues.
b. Workaround "linked project". Outcome - Can't *guarantee** but this should also work.
With option 'b'
In your comment you mentioned.
but I'm still not sure what it does or how to implement a 'linked
project', do you have any more information on this? Also, as this is
for a group university project, I was hoping i wouldn't have to force
too many workarounds
When you think about it, it is not really hard work around. It is simple and I'm sure your group would be able to apply this workaround easily.
Please follow the below steps.
Create a separate class library in your solution (you can target .NET framework 4).
Then add NUnit assemblies and the NUnit test adapter as usual.
Right click on this project and select 'Add' then 'Existing Item'
Select the Win8 Store Unit Test project and locate the Unit Test file you want to add. When you add the file, make sure you select 'Add As a Link' button. Please see below.
Now rebuild the solution, close and re-open the UnitTest explorer and you should be able to run those tests.
*The reason I said can't guaranteed. I haven't really written Unit tests against Win8 App. So if your SUT (System Under Test) require special configuration it might cause issues. But I'm not sure.
Finally creating a link files are not that hard if everything works you can continue to do this until NUnit has the support for Win8 Unit Testing. Or the other option is simply change all your Unit Tests to use MSTest framework if possible.

Running unit tests

In our solution we have several test projects. Most of them contain unit tests that run fast but some are for integration, acceptance and UI tests which take quite some time to finish.
Now I'd like to have a convenient way of running only the unit tests. Either by using the hotkey to run all or using the new feature to run tests after each build.
Unfortunately VS also runs all the slow tests as well. In VS10 I grouped the tests in Test View by project and selected only the ones containing unit tests. It's not as easy as I wished it to be but at least it was possible. Now there doesn't seem to be a way around running all tests in a solution.
The only alternative that I see at the moment is to remove all but the unit tests from the solution but this would limit the refactoring capabilities.
So does anyone know how to easily group and run only unit tests in the new VS?
In Visual Studio 2012 Update 1 CTP, Test Explorer has added the option to group tests by Project or Traits (Categories).
Please go to this link to see what's new there.
You can use the search filter in Unit Text Explorer.
In the new Test Exlorer shipped with 2012, you can group tests by 'Test Results', 'FileName',... etc but in RTM build group/search by 'TestCategory' is not present from Test Explorer. However there is a filter in commandline and TeamBuild based on TestCategory (Running selective unit tests in VS 2012 RC using TestCaseFilter) in VS2012.
From a member of VS dev Team, they understood the importance of this missing feature. It is in the backlog, and it should be available in furutre builds/updates.
The following blog provides more details: http://blogs.msdn.com/b/vikramagrawal/archive/2012/07/23/running-selective-unit-tests-in-vs-2012-rc-using-testcasefilter.aspx
As of Visual Studio 2012 Update 2 (currently on CTP) now we are able to run a subset of unit test using "Playlists" or based on "Lists & Classes". More information here: http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/first-ctp-for-visual-studio-update-2.aspx#playlists
Original Answer:
AFAIK, The new unit testing framework in VS2012 "supports selective execution based on filtering condition through TestCaseFilter". Unfortunately, currently there is not support to do this through the user interface but it is in the product group's backlog. You can use this approach through Test Build or command line. Please refer to the following blog: http://blogs.msdn.com/b/vikramagrawal/archive/2012/07/23/running-selective-unit-tests-in-vs-2012-rc-using-testcasefilter.aspx
EDIT: Following the MSDN documentation to use test categories to group tests.
http://msdn.microsoft.com/en-us/library/dd286595.aspx
Also, refer to this question: How to exclude certain tests in the Visual Studio 2012 Test Runner?
It shows an example of filtering based on the test path.
I'd recommend using TestDriven.Net. Group all Unit Testing projects in one solution folder, and all other tests in another. Then just right click the "Unit Tests" folder and choose "Run All Tests". I always favor this great test runner of the VS native testing tools.
Another approach is using NCrunch - It runs all you tests in the background while you code. It handles integration tests pretty well, as they run in parallel, in the background so it doesn't block you (you also choose which test projects are run). One catch though - I believe it doesn't support VS2012 yet, but probably soon.
I was also missing this feature... (We did the same as you did: grouping by project or sometimes by namespace). But I found that I could somehow workaround this using the test explorer search capabilities:
https://msmvps.com/blogs/deborahk/archive/2012/09/16/searching-and-grouping-in-vs-2012-test-explorer.aspx
In my case I could identify the specific tests I needed to run using the search filter on FullName (use dropdown on search box, or type FullName:"UnitTest")
Its not the same, but it works for me

Debugging unit tests with resharper

I've just started using resharper and I found a very annoying thing about it. When debugging a unit test, I try to step-into (F11) a method, but visual studio complains that source code is not available. The problem is that resharper is wrapping method calls with its own classes. Of course I can put a braeakpoint further in my source, but this is very annoying. Do you know if thereĀ“s a solution for this? By the way, I'm using NUnit to write my tests
Thanks
Federico
After some playing around I managed to recreate this on my setup (Xunit.net in resharper, visual studio 2008)... The steps I took to recreate this are:
Set the dll that contains the tests as the startup project (I know you don't need to do this, was just trying to get it to fail)
Put a breakpoint in the unit test
Push F11 (the shortcut key for 'step into' in my configuration)
This complains 'Cannot start test project 'RowanBeach.Crm.Domain.Test' because the project does not contain any tests.'
Run the 'Debug Unit Tests' command from the Resharper menu (I have this bound to a key combination on my machine)
This displays the 'No source code available...' message
Of course that's not how you should start unit tests from resharper! :) If that's what you were doing (or something similar), try this instead:
Don't bother setting the dll as the startup project - it doesn't need to be
build or rebuild the dll that contains the tests
set the breakpoint
Put the cursor somewhere in the source code for the unit test you want to debug to set it as the 'current context' unit test
Run the 'Debug Unit Tests' command from the Resharper menu (You might want to bind this to a key combination if you haven't already)
Hopefully, that should work
What type of tests are you running - NUnit? MS Test? Something else?
I've never found it difficult to debug tests using R# - just put a breakpoint in your test and go. What method are you trying to step into? I've generally not tried to step into the NUnit methods themselves (assertions etc) but stepping into your own code should be okay.
If you can come up with a quick example, I'd be happy to try it myself.