저는 Moq 프레임 워크와 C#을 처음 접했습니다. 내 [설정] 함수에서 VS 2010 Express와 NUnit를C# 교육용 Moq가 스위트 룸의 첫 번째 테스트에서 작동하지 않습니다.
을 사용하고, 내가 가진 : 그 후 각 시험은 빈 목록을 가져옵니다 동안
이this.mockAllianceController = new Mock<AllianceController>();
this.mockAllianceController.Setup(ac => ac.getAllies(this.currentRealm)).Returns(new List<string>());
...
this.testObj = new DiplomacyLogic(this.mockAllianceController.Object);
제품군의 첫 번째 테스트가 널이 반환 도착 . 내가 뭘 놓치고 있니?
업데이트 : 시험
코드 :
public void ApplyRelations() {
List<string> allies = this.AllianceController.getAllies(this.RealmName);
foreach (string ally in allies) {
...
}
}
public virtual List<string> getAllies(string realm) {
...
}
두 테스트 케이스 : bTest 잘 통과하면서
이[Test]
public void aTest() {
this.testObj.ApplyRelations();
}
[Test]
public void bTest() {
this.testObj.ApplyRelations();
}
ATEST는 NullReferenceException이 발생합니다. 어떤 도움이 필요합니까?
첫 번째 테스트 코드를 게시하십시오. –
나는 doofus입니다. 설치 후 this.currentRealm을 초기화했습니다. XD 첫 번째 테스트가 실패한 이유는 실제 질문이 아니지만 두 번째 테스트가 통과 한 이유는 무엇입니까? [TearDown]없이 this.currentRealm이 파괴되지 않았나요? – Shane