Professional.Test.Driven.Development.with.Csharpの例に従って います。コードを C# から VB に変換しています。(この例は第 7 章の始まりです)
今持っている
Public Class ItemType
Public Overridable Property Id As Integer
End Class
Public Interface IItemTypeRepository
Function Save(ItemType As ItemType) As Integer
End Interface
Public Class ItemTypeRepository
Implements IItemTypeRepository
Public Function Save(ItemType As ItemType) As Integer Implements IItemTypeRepository.Save
Throw New NotImplementedException
End Function
End Class
そしてTestUnitプロジェクトで
<TestFixture>
Public Class Specification
Inherits SpecBase
End Class
vb.net でテストを作成すると (失敗するはずです)、問題なくパスします (整数値 0 = 0)。
Public Class when_working_with_the_item_type_repository
Inherits Specification
End Class
Public Class and_saving_a_valid_item_type
Inherits when_working_with_the_item_type_repository
Private _result As Integer
Private _itemTypeRepository As IItemTypeRepository
Private _testItemType As ItemType
Private _itemTypeId As Integer
Protected Overrides Sub Because_of()
_result = _itemTypeRepository.Save(_testItemType)
End Sub
<Test>
Public Sub then_a_valid_item_type_id_should_be_returned()
_result.ShouldEqual(_itemTypeId)
End Sub
End Clas
C# の同じコードを参照するためだけに。テスト失敗
using NBehave.Spec.NUnit;
using NUnit.Framework;
using OSIM.Core;
namespace CSharpOSIM.UnitTests.OSIM.Core
{
public class when_working_with_the_item_type_repository : Specification
{
}
public class and_saving_a_valid_item_type : when_working_with_the_item_type_repository
{
private int _result;
private IItemTypeRepository _itemTypeRepository;
private ItemType _testItemType;
private int _itemTypeId;
protected override void Because_of()
{
_result = _itemTypeRepository.Save(_testItemType);
}
[Test]
public void then_a_valid_item_type_id_should_be_returned()
{
_result.ShouldEqual(_itemTypeId);
}
}
}
テストは次の行で失敗します:
_result = _itemTypeRepository.Save(_testItemType);
オブジェクト参照がオブジェクト インスタンスに設定されていません。