如何使用 MSpec 在 Behavior 类 中获取 Intellisense?
How do I get Intellisense inside Behavior classes using MSpec?
我正在使用 MSpec-Framework 为我们的新项目实施 BDD。我对 BDD 的概念很陌生,因此对 MSpec 也是如此,并且在处理感兴趣的对象(示例中的 _obj2)时遇到问题,至少 Visual Studio intellisense 没有在 Behavior-Class
中提出它,特别是在 should_do_some_fancy_magic
-上下文中。
namespace exampleSpace{
public partial class ExampleClass{
private ObjectOfAnotherClass _obj2
private void Test(ObjectOfAnotherClass _co)
...
}
}
namespace exampleSpace.Test{
[Behaviors]
class ExampleClassBehavior{
Establish context =()=>{...};
It should_do_some_fancy_magic() =()=>
ShouldBeEqual(ExampleValue, _ex.Test(_ex._obj2);
private static ExampleClass _ex;
}
}
关于如何让智能感知在 Behavior-Class
中工作的任何想法?
您不需要为上下文设置 [Behaviors]
。行为用于在上下文之间重用 It
。这是一个很少出现的用例。
尽管未经测试,这应该可以工作:
namespace exampleSpace{
public partial class ExampleClass {
public void Test(ObjectOfAnotherClass _co)
_co.Foobar = 42;
}
}
namespace exampleSpace.Test {
[Subject(typeof(ExampleClass))] // This is optional.
class When_something_happens
{
static ObjectOfAnotherClass Other;
static ExampleClassOther SystemUnderTest ;
Establish context = () => {
Other = new ObjectOfAnotherClass();
SystemUnderTest = new ExampleClass();
}
Because of = () => {
SystemUnderTest.Test(Other);
}
It should_do_some_fancy_magic() =
() => Other.Foobar.ShouldEqual(42);
}
}
你可以看看some MSpec samples here。
我正在使用 MSpec-Framework 为我们的新项目实施 BDD。我对 BDD 的概念很陌生,因此对 MSpec 也是如此,并且在处理感兴趣的对象(示例中的 _obj2)时遇到问题,至少 Visual Studio intellisense 没有在 Behavior-Class
中提出它,特别是在 should_do_some_fancy_magic
-上下文中。
namespace exampleSpace{
public partial class ExampleClass{
private ObjectOfAnotherClass _obj2
private void Test(ObjectOfAnotherClass _co)
...
}
}
namespace exampleSpace.Test{
[Behaviors]
class ExampleClassBehavior{
Establish context =()=>{...};
It should_do_some_fancy_magic() =()=>
ShouldBeEqual(ExampleValue, _ex.Test(_ex._obj2);
private static ExampleClass _ex;
}
}
关于如何让智能感知在 Behavior-Class
中工作的任何想法?
您不需要为上下文设置 [Behaviors]
。行为用于在上下文之间重用 It
。这是一个很少出现的用例。
尽管未经测试,这应该可以工作:
namespace exampleSpace{
public partial class ExampleClass {
public void Test(ObjectOfAnotherClass _co)
_co.Foobar = 42;
}
}
namespace exampleSpace.Test {
[Subject(typeof(ExampleClass))] // This is optional.
class When_something_happens
{
static ObjectOfAnotherClass Other;
static ExampleClassOther SystemUnderTest ;
Establish context = () => {
Other = new ObjectOfAnotherClass();
SystemUnderTest = new ExampleClass();
}
Because of = () => {
SystemUnderTest.Test(Other);
}
It should_do_some_fancy_magic() =
() => Other.Foobar.ShouldEqual(42);
}
}
你可以看看some MSpec samples here。