MSpec,我应该在 [Subject()] 属性中放入什么?

发布于 2024-11-30 18:04:40 字数 392 浏览 5 评论 0原文

我已经使用 MSpec 一段时间了,我真的很喜欢它。我发现要让 ReSharper 识别我的规范,我需要使用 SubjectAttribute

但我想知道,在 [Subject()] 属性中放置的最佳内容是什么?

如果我正在做 BDD,那么我不知道被测试的类型,因此 [Subject(typeof(thingy))] 似乎还为时过早。我想一旦编写了代码就可以添加。

这样就剩下文本版本了,[Subject("some text")]。但放在那里最好的东西是什么?

无论我做什么,它似乎都不会影响我在 ReSharper 中获得的输出。我想在某种程度上这取决于个人喜好,但我想知道这里是否有任何约定?

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

I'm wondering though, what's the best thing to put in the [Subject()] attributes?

If I'm doing BDD, then I don't know the type under test so [Subject(typeof(thingy))] seems premature. Could be added later I suppose once the code is written.

So that leaves the text version, [Subject("some text")]. But what's the best thing to put there?

Whatever I do, it doesn't seem to affect the output I get in ReSharper. I suppose to some extent this is down to personal preference, but I wondered if there was any convention here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪化雨蝶 2024-12-07 18:04:40

您不需要应用 SubjectAttribute 来让 ReSharper 识别上下文和规范,包含 It 字段的类就足够了。但是,如果您希望 ReSharper 支持 MSpec 类型和字段的自定义命名约定(Because 等),您需要应用 SubjectAttribute

  1. 定义自定义命名约定锐锐 |选项|
    语言/公共部分 |命名风格|高级设置

    添加用户定义的命名规则时,向下滚动列表以查看 MSpec 实体。

  2. 在 ReSharper 中启用 MSpec 注释 |选项|代码检查/代码注释部分

    注释 + SubjectAttribute(即使没有自定义命名规则)会阻止 ReSharper 将 MSpec 的字段标记为未使用。或者,在项目设置中禁用警告 169。

Subject 用作描述您的上下文的元数据,例如您可以使用被测系统(编写单元测试时)、您选择的字符串或两者。这些信息将在 HTML 和 ReSharper 输出中报告。目前还无法正常工作,我怀疑这是ReSharper 6.0 运行程序。

与字符串一样,您基本上可以在那里放置任何您想要的东西。我建议使用该主题按功能对您的规格进行分组。

主题:登录

上下文:使用有效凭据登录时、使用无效凭据登录时等

。 Watin.Specs/LoginSpecs.cs" rel="nofollow">我的 GitHub 存储库中的示例。

You don't need to apply SubjectAttribute to have ReSharper recognize contexts and specifications, a class containing an It field will suffice. However, if you want ReSharper to support custom naming conventions for MSpec types and fields (Because et al) you need to apply the SubjectAttribute:

  1. Define custom naming conventions in ReSharper | Options |
    Languages/Common section | Naming Style | Advanced Settings

    When you add a User defined naming rule scroll down the list to see MSpec entities.

  2. Enable MSpec annotations in ReSharper | Options | Code Inspection/Code Annotations section

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

Subject serves as metadata describing you context, for example you can use the System Under Test (when writing a unit test), a string of your choice, or both. These information will be reported in the HTML and in the ReSharper output. It doesn't work as of now, I suspect this is a bug in the ReSharper runner for 6.0.

As with strings, you can basically put anything you want there. I would recommend using the subject to group your specs by feature.

Subject: Login

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

There's an example in my GitHub repository.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文