Use file layout to group NUnit tests by Category

Hi,

I am trying to use ReSharper's file layout feature to reorder my NUnit classes according to the following rule :

  • [Setup] first
  • then, [Test]
  • finally, [Up] then [Down]

The sort works perfectly, relying on attributes types to group the entries. Now, if I have several tests regarding the same category (NUnit.Framework.CategoryAttribute), I would like to be able to group them together first, sort them inside of this group, then sort all the categories (and uncategorized tests if any, coming first or last I do not care).
Is there a way to create a group dynamically based on an attribute ? In this case, the attribute is used like this :

[Category("Tests regarding that"]
[Test]
public void TestThat(){}

[Category("Tests regarding that"]
[Test]
public void TestThatError(){}

I would even take a solution involving the use of a regex if needed.

Thank you !

4 comments
Comment actions Permalink

Hi Serge Aradj!

I am afraid I barely catch the idea you proposing.

How I understood the process for now:

  1. Group tests by categories
  2. Sort inside groups, by name, for example.
  3. then sort all the categories (and uncategorized tests if any, coming first or last I do not care) ??

But you specify the order of categories in the layout constructor.. Do you mean to sort attribute groups in alphabetic eg order based on attribute/category value?

 

Is there a way to create a group dynamically based on an attribute ? 

Do you mean to automatically create a file-layout pattern with grouped by attribute objects?

0
Comment actions Permalink

Hi !

You understood my need quite well Alexander ! I would like to sort methods based not only on their own name but also on the value of one of their attributes.

For example, I would like this randomly sorted file

[Test]
[Category("Set activity.CorrelationId")]
public void EndTask_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set status to Succeeded")]
public void Succeed_SucceedATopLevelActivity_ShouldSetTheStatusToSucceeded()
{...}

[Test]
[Category("Set activity.CorrelationId")]
public void Fail_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set status to Failed")]
public void Fail_FailAMonitoredActivity_ShouldSetTheStatusToFailed()
{...}

[Test]
[Category("Set status to Failed")]
public void Fail_FailATopLevelActivity_ShouldSetTheStatusToFailed()
{...}

[Test]
[Category("Set activity.CorrelationId")]
public void Progress_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set status to Warning")]
public async Task Warn_WarnAMonitoredActivity_ShouldSetTheStatusToWarning()
{...}

[Test]
[Category("Set activity.CorrelationId")]
public void Succeed_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set status to Succeeded")]
public async Task Succeed_SucceedAMonitoredActivity_ShouldSetTheStatusToSucceeded()
{...}

[Test]
[Category("Set activity.CorrelationId")]
public void Warn_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

To end up sorted by Category, then by method name, like so :

Test]
[Category("Set activity.CorrelationId")]
public void EndTask_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set activity.CorrelationId")]
public void Fail_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set activity.CorrelationId")]
public void Progress_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set activity.CorrelationId")]
public void Succeed_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set activity.CorrelationId")]
public void Warn_CorrelationIdIsInContext_ActivityGetsTheSameCorrelationId()
{...}

[Test]
[Category("Set status to Failed")]
public void Fail_FailAMonitoredActivity_ShouldSetTheStatusToFailed()
{...}

[Test]
[Category("Set status to Failed")]
public void Fail_FailATopLevelActivity_ShouldSetTheStatusToFailed()
{...}

[Test]
[Category("Set status to Succeeded")]
public async Task Succeed_SucceedAMonitoredActivity_ShouldSetTheStatusToSucceeded()
{...}

[Test]
[Category("Set status to Succeeded")]
public void Succeed_SucceedATopLevelActivity_ShouldSetTheStatusToSucceeded()
{...}

[Test]
[Category("Set status to Warning")]
public async Task Warn_WarnAMonitoredActivity_ShouldSetTheStatusToWarning()
{...}
0
Comment actions Permalink

Hi Serge Aradj!

Such functionality is indeed yet to implement in ReSharper.

In order to address the question, I have created a feature request in our tracker.

Please vote or left a comment to give this feature more chances to be added in upcoming releases. 

Thank you for the input, and have a nice day!

0
Comment actions Permalink

Hi Alexander, I just did :) !

Thank you for submitting my feature request !

0

Please sign in to leave a comment.