我是新來的c#以及Moq框架。我使用VS 2010 Express和NUnit的Moq for c#training不適用於套件中的第一個測試
在我的[設置]功能,我有:
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) {
...
}
兩個測試用例:
[Test]
public void aTest() {
this.testObj.ApplyRelations();
}
[Test]
public void bTest() {
this.testObj.ApplyRelations();
}
ATEST將同時BTEST經過精細拋出NullReferenceException異常。任何幫助?
發佈第一次測試的代碼。 –
我是一個doofus。安裝程序後,我初始化this.currentRealm。 XD 所以真正的問題不是爲什麼第一次測試失敗,但爲什麼第二次測試通過?我猜沒有[TearDown],this.currentRealm沒有被破壞? – Shane