MSpec, what should I put in my [Subject ()] attributes?

I have been using MSpec for a while, and I really like it. I found that in order to get ReSharper to recognize my specifications, I need to use SubjectAttribute .

I am wondering what is the best way to add [Subject()] attributes?

If I am doing BDD, then I don’t know the type of test, so [Subject(typeof(thingy))] seems premature. May be added later, I suppose, as soon as the code is written.

So this leaves a text version of [Subject("some text")] . But what is the best place there?

Whatever I do, this does not seem to affect the output I get in ReSharper. I suppose, to some extent, it depends on personal preferences, but I thought, is there any agreement here?

+7
source share
1 answer

You do not need to use SubjectAttribute to recognize the contexts and specifications of ReSharper, just the class containing the It field is enough. However, if you want ReSharper to support custom naming conventions for MSpec types and fields ( Because et al), you need to use SubjectAttribute :

  • Define User Naming Conventions in ReSharper | Options | Languages ​​/ General Section | Naming Style | Advanced settings

    When adding a custom naming rule, scroll down to see MSpec objects.

  • Enable MSpec Annotations in ReSharper | Options | Code Verification / Annotation Code Section

    Annotations + SubjectAttribute (even without custom naming rules) prevent ReSharper from marking MSpec fields as unused. Alternatively, turn off warning 169 in the project settings.

Subject serves as metadata that describes your context, for example, you can use the System Under Test (when writing a unit test), a string of your choice, or both. This information will be presented in HTML and in the output of ReSharper. This does not work at the moment, I suspect that this is a bug in the ReSharper runner for 6.0.

As with strings, you can put whatever you want. I would recommend using a theme to group my feature specifications.

Subject: Login

Contexts: when logging in with valid credentials, when logging in with invalid credentials, etc.

There is a GitHub in my repository .

+11
source

All Articles