ReSharper and xUnit.net

Those of you who have switched over to xUnit.Net may have a received a nasty surprise with the 'type members layout' feature of ReSharper: it doesn't respect method attributes. Namely, you can tell it to not reorder methods in an NUnit fixture like this: 

 <Pattern>   
 <Match>   
    <HasAttribute CLRName="NUnit.Framework.TestFixture"/>   
  </Match>   
</Pattern>

But you cannot tell it to not reorder your xUnit methods like this:  

 <Pattern> 
       <Match> 
         <And Weight="100"> 
           <Kind Is="method"/> 
           <HasAttribute CLRName="Xunit.TestAttribute" Inherit="false"/> 
          </And> 
       </Match> 
</Pattern>

Apparently it will only look for attributes on classes and interfaces. In the meantime, I think the simplest solution is to just create a fake attribute you can add to your fixture. 

 public class ReSharperNoReorderAttribute : Attribute 
{ 
}

And the appropriate pattern match to ReSharper:

 <Pattern>
       <Match> 
          <HasAttribute CLRName="ReSharperNoReorder"/> 
      </Match> 
</Pattern>

All should be well after that.

Comments

  • Anonymous
    October 02, 2007
    This sounds quite strange. What do you mean with "don't reorder method"??? It's clear when entire class members are not re-layouted, but how can you not reorder single member????Anyway, feel free to contact me at Eugene.Pasynkov (at) jetbrains.com to solve this problem in the future
  • Anonymous
    October 03, 2007
    All I'm saying is that I don't want to re-order methods that are matched by a given attribute.The documentation, as it is, doesn't say that I can't use the <match> attribute for <kind is="method"> and <HasAttribute CLRName> together, so why would I assume this wouldn't work? :)Just for reference, xUnit doesn't have a [Fixture] class attribute like NUnit and MSTest do. I still don't want my unit tests re-ordered.
  • Anonymous
    October 03, 2007
    The comment has been removed
  • Anonymous
    October 04, 2007
    It's even more than that. You don't want ANYTHING in the class to be rearranged if the class has [Test] methods.
  • Anonymous
    October 04, 2007
    True. If there are non-[Test] methods, I want them left exactly where they are.