为什么在此 MSpec 测试中出现 NullReferenceException?
Why do I get a NullReferenceException in this MSpec test?
所以我安装了这些 nuget 包:
在这些参考文献中达到顶峰:
我使用 NCrunch。我有这个规格:
namespace GlobPatternMatching.Tests
{
using FluentAssertions;
using Machine.Fakes;
using Machine.Specifications;
[Subject(typeof(GlobMatching))]
public class When_Given_Literal : WithSubject<GlobMatching>
{
private static string pattern = "path";
private static string[] result;
private Establish context => () =>
{
pattern = "path";
};
private Because of => () => result = Subject.GetGlobs(pattern);
private It should_return_path_in_the_array = () =>
{
result[0].Should().Be("path");
};
}
}
为此class:
namespace GlobPatternMatching
{
using System;
public class GlobMatching
{
public string[] GetGlobs(string pattern)
{
return pattern.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
}
}
}
直接进行 TDD,我得到空引用异常。当我调试时,我无法逐步执行该方法,并且所有规范 class 字段均为空.....
我不觉得我遗漏了什么,但如果你不介意看一看并弄清楚我在这里做错了什么,那会很好。我正在使用最新的 VS2015、NCrunch 等...
你不会相信这是什么问题...
private Establish context => () =>
{
pattern = "path";
};
private Because of => () => result = Subject.GetGlobs(pattern);
我用 =>
代替了 =
.....
// ----------------------\/-------
private Establish context = () =>
{
pattern = "path";
};
// ----------------\/------------
private Because of = () => result = Subject.GetGlobs(pattern);
所以我安装了这些 nuget 包:
在这些参考文献中达到顶峰:
我使用 NCrunch。我有这个规格:
namespace GlobPatternMatching.Tests
{
using FluentAssertions;
using Machine.Fakes;
using Machine.Specifications;
[Subject(typeof(GlobMatching))]
public class When_Given_Literal : WithSubject<GlobMatching>
{
private static string pattern = "path";
private static string[] result;
private Establish context => () =>
{
pattern = "path";
};
private Because of => () => result = Subject.GetGlobs(pattern);
private It should_return_path_in_the_array = () =>
{
result[0].Should().Be("path");
};
}
}
为此class:
namespace GlobPatternMatching
{
using System;
public class GlobMatching
{
public string[] GetGlobs(string pattern)
{
return pattern.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
}
}
}
直接进行 TDD,我得到空引用异常。当我调试时,我无法逐步执行该方法,并且所有规范 class 字段均为空.....
我不觉得我遗漏了什么,但如果你不介意看一看并弄清楚我在这里做错了什么,那会很好。我正在使用最新的 VS2015、NCrunch 等...
你不会相信这是什么问题...
private Establish context => () =>
{
pattern = "path";
};
private Because of => () => result = Subject.GetGlobs(pattern);
我用 =>
代替了 =
.....
// ----------------------\/-------
private Establish context = () =>
{
pattern = "path";
};
// ----------------\/------------
private Because of = () => result = Subject.GetGlobs(pattern);