Right click context menu in unit test session; possible to add a menu item?

Hi,

I was wondering if there is a way to add a menu item to Resharper NUnit Unit_Test_Session right click context menu thru SDK and if it is possible to get any information about the particular test being right clicked?

I looked thru SDK documentation but could not find an answer. Also on this topic, what would be the recommended way of getting menubat and context menus paths such as (UnitTestSession.ActionBar or ReSharper.Navigate).

Thanks,

Bred

2 comments
Comment actions Permalink

Hi Bred. I'm assuming you mean the Unit Test Session window, which displays the tests as they are run.
You should be able to add actions to the context menu by editing your actions.xml file and adding your items to the action group called "UnitTestSession.ContextMenu". Which would be something like this:

<insert group-id="UnitTestSession.ContextMenu" position="last">
  <action id="my_action" text="Do something" />
</insert>

Alternatively, you could try adding to the group "UnitTest.ContextMenu", which is embedded in a number of places, and shows the run, debug, cover, etc. actions.
You can get access to the selected unit test(s) from the IDataContext passed in to the Update and Execute methods of the IActionHandler interface your action implements. Firstly, you can call:

var session = context.GetData(TreeModelBrowser.TREE_MODEL_DESCRIPTOR) as UnitTestSession;

to get the UnitTestSession object (check for null before using it, just in case), and you can get at the unit test elements with:

var elements = context.GetData(UnitTestDataConstants.UNIT_TEST_ELEMENTS);

which will return either null, or a UnitTestElements structure, which will give you all of the currently selected unit tests.
As for getting at the list of actions and action groups used in the menus and action bars, there is no readily available means of getting at them, and it does require dotPeek to get them. I'll add a work item to get an easier way of finding and using this information, ideally documented in the dev guide.
Let me know if you have any problems.
Thanks
Matt

0
Comment actions Permalink

Thanks Matt!

This exactly what I needed.

Bred

0

Please sign in to leave a comment.