如何命名 xSpecification/BDD 测试类以便它们传达意图?特别是在解决方案资源管理器中
我最近强烈采用了 BDD 设计以及使用 MSpec 来实现 xSpecification 测试。这导致了一些相当疯狂的类名,这些类名很难在解决方案资源管理器中区分意图。举个例子:
[Subject(typeof(MuchGoodServiceOrchestrator))]
public class Given_i_am_a_logged_user_and_view_my_some_company_super_things
: WithSubject<MuchGoodServiceOrchestrator>
我最初的一些想法可能是使用解决方案文件夹并执行类似的操作
Given_I_am_logged_in \ When_I_view_my_some_company_super_things.cs
这将允许我进一步深入
Given_I_am_logged_in \ And_things_are_good \ When_I_view_my_some_company_super_things.cs Given_I_am_logged_in \ And_things_are_bad \ When_I_view_my_some_company_super_things.cs
有没有人成功地做了类似的事情,或者您在命名 xSpecification 测试中发现了什么成功?
I've recently adopted strongly following BDD design along with usage of MSpec for implementing xSpecification tests. This has been leading to some rather insane class names that become hard to distinguish intent inside the solution explorer. Take for example:
[Subject(typeof(MuchGoodServiceOrchestrator))]
public class Given_i_am_a_logged_user_and_view_my_some_company_super_things
: WithSubject<MuchGoodServiceOrchestrator>
Some of my initial thoughts have been perhaps to use solution folders and do something like
Given_I_am_logged_in \ When_I_view_my_some_company_super_things.cs
This would allow me to potentially drill down further
Given_I_am_logged_in \ And_things_are_good \ When_I_view_my_some_company_super_things.cs
Given_I_am_logged_in \ And_things_are_bad \ When_I_view_my_some_company_super_things.cs
Has anyone had success doing something similar, or what have you found success with in naming xSpecification tests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
警告:我不是这方面的专家,而且我是孤立工作的,但这是我基于几个月的反复试验得出的个人看法。
subject 属性
[Subject(Type subjectType, string subject)]
也许您可以使用字符串参数来记录您的担忧,因此您可能会使用类似以下内容的内容:
-and-
对此进行一些扩展,如果你正在使用约定
这是表达<的另一种方式em>安排、行动、断言模式。 给定(安排)是您的上下文,是测试的先决条件。 何时 (行动) 是您正在测试的活动,然后< /em> (断言) 是您验证预期行为的地方。
在 MSpec 中,我通常使用这种模式:
因此尝试使用问题域中的术语:
Caveat: I'm not an expert at this and I work in isolation, but this is my personal take based on several months of trial and error.
There's an overload of the subject attribute
[Subject(Type subjectType, string subject)]
Perhaps you could use the string parameter to document your concern, so perhaps you'd use something like:
-and-
Expanding on that a bit, if you are using the convention
That is another way of expressing the Arrange, Act, Assert pattern. The Given (Arrange) is your context, the preconditions for the test. The When (Act) is the activity you're testing and the Then (Assert) is where you verify expected behaviour.
in MSpec, I usually use this pattern:
So to try to use terms from your problem domain:
将给定对象的所有测试类分组到一个文件下,例如 SuperThingTests 将包含围绕 SuperThing 类的所有测试。
Group all the test classes for a given object under one file e.g. SuperThingTests would contain all of your tests around the SuperThing class.