2016-10-05 4 views
0

그래서 나는이 nuget 패키지가 설치되어 : 이 MSpec 테스트에서 NullReferenceException이 발생하는 이유는 무엇입니까?

Nuget

이 참조에서 남중 :

References

내가 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"); 
      }; 
    } 
} 

: :이 사양을 똑바로

namespace GlobPatternMatching 
{ 
    using System; 

    public class GlobMatching 
    { 
     public string[] GetGlobs(string pattern) 
     { 
      return pattern.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); 
     } 
    } 
} 

TDD'ing, 내가 null 참조 예외를 얻을. 내가 디버깅 할 때 메서드를 통해 단계를 수행 할 수없고 모든 spec 클래스 필드가 null입니다 .....

나는 아무것도 놓치지 않는 것 같지 않지만, 여기에서 내가 잘못한 것을보고 모양 짓는 것이 좋을 것입니다. 내가 최근 VS2015를 사용하고, NCrunch는 등 ...

답변

2

당신은 문제가 무엇인지 믿지 않을 것 ...

private Establish context =>() => 
{ 
    pattern = "path"; 
}; 

private Because of =>() => result = Subject.GetGlobs(pattern); 

내가 넣었습니다 => 대신 =의 ....

// ----------------------\/------- 
private Establish context =() => 
{ 
    pattern = "path"; 
}; 

// ----------------\/------------  
private Because of =() => result = Subject.GetGlobs(pattern); 
관련 문제