Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I share ReSharper Unit Test Sessions across a team?

I have set up two permanent test sessions in ReSharper 7 in Visual Studio 2010/2012 - "Passing" and "Failing". I run the Passing session daily and can quickly identify any regression failure since the last time in which case I move those tests into Failing, where I can work on it when I get time. It works and it's great.

The problem is that I can't find any way to export those sessions as a "Solution Team-Shared" option, as suggested in the ReSharper docs for settings you might want to share across a team. Obviously, it'd be beneficial to be able to have others in the time avail of the same test session structure. But when I change my sessions, it only ever seems to update the 'PatientPortal.sln.DotSettings.user' file, not the 'PatientPortal.sln.DotSettings' one.

In RESHARPER -> Options -> Unit Testing, I have checked 'Save and restore Unit Test Sessions' and have selected Save-To - 'Solution [name] Team-shared'

Because of the difficulty I'm experiencing, I suspect that ReSharper unit test sessions are not designed to be something you check-in and share, but I'd find it productive to do so in this case, so does anyone know how to do this?

like image 849
Ralph Lavelle Avatar asked Aug 24 '12 01:08

Ralph Lavelle


People also ask

How do you carry out unit testing?

A typical unit test contains 3 phases: First, it initializes a small piece of an application it wants to test (also known as the system under test, or SUT), then it applies some stimulus to the system under test (usually by calling a method on it), and finally, it observes the resulting behavior.

How do I run unit tests with ReSharper?

Right click on the project or solution in the VS solution-explorer and choose 'Run Unit Tests' Or go to the Resharper menu, choose Unit-Testing and choose one of the options from there.

How do you add MSTest to a project?

On the File menu, select New > Project, or press Ctrl+Shift+N. On the Create a new project page, type unit test into the search box. Select the project template for the test framework that you want to use, for example MSTest Test Project or NUnit Test Project, and then select Next.


3 Answers

There is an open ticket for a save unittest sessions feature:

RSRP-275264 Add action to save unit tests session

I hope we'll get this feature in the future. Maybe it helps if you vote it up or post a comment about your usecase.

like image 89
Sebastian Avatar answered Sep 27 '22 17:09

Sebastian


You should use categories for this. If you are using NUnit, then you can use CategoryAttribute to mark your tests or test fixtures with categories, like this:

[Category("Failing")] public void MyTestProc() ...

You can specify several categories for one test (just use attribute several time). Afterwards go to ReSharper | Unit Tests | Unit Tests and select Group by -> Categories (or something like that, don't remember exactly). Select your category and press a button Run selected tests from toolbar.

like image 21
Dmitry Osinovskiy Avatar answered Sep 27 '22 16:09

Dmitry Osinovskiy


The short answer is that you're right - resharper test sessions are intended to be saved per user, and get saved in the .sln.DotSettings.user file, and .user files aren't supposed to be checked in.

For most scenarios, I'm not sure it makes sense to share across the team - if I'm TDDing a certain class, other members in the team don't need to see my tests, as they won't be working in the same area of the code, and will instead have their own sessions. A knock on effect will also be a lot of churn (and high risk of conflicts) on that part of the shared settings file.

Selecting "Save To" for a team shared settings file will only cause the setting of "save and restore unit test sessions" to the shared settings file. It won't cause the sessions themselves to be saved.

I haven't spent too long thinking about it, but I suspect you could write a ReShaprer plugin that saved locked sessions to the team shared settings. The UnitTestSessionManager raises events when a session is created or closed, and the IUnitTestSession interface exposes GetPersistentInfo and RestorePersistentInfo which would allow you to get at the data to save and load. It would then be a case of persisting the data to the settings file at appropriate times.

I can't guarantee that you won't get conflicts in this file, though - I don't know what order the elements are in when they are serialised, and the data is serialised into quite a dense format, so changes to the sessions could be painful.

Perhaps a different way of working would be better? What are the two sessions showing you that you wouldn't get just by running all the tests in a single session? ReSharper allows you to show just passing or just failing tests. Does it really help the team to be able to group tests into passing or failing? Perhaps adding categories to the tests you need to fix later? Mark them ignored if they're not important enough to fix right now? Fix them right now?

like image 34
citizenmatt Avatar answered Sep 27 '22 17:09

citizenmatt