我是单元测试的新手。单元测试在下面是成功的。我预计他们会失败,因为 Student.getCourse、unidergraduate.getCourse1 和 postgraduate.getcourse1 返回不同的值给正在测试的内容,例如“学生课程”<>“学生课程 1”。
Imports NUnit.Framework
Imports NMock
Imports StudentCL
Namespace Test
<TestFixture()>
Public Class StudentTest
Private _mocks As MockFactory
Private _StudentMock As Mock(Of Student)
Private _GraduateMock As Mock(Of Graduate)
Private _UndergraduateMock As Mock(Of UnderGraduate)
<SetUp()>
Public Sub SetUp()
_mocks = New MockFactory()
_StudentMock = _mocks.CreateMock(Of Student)()
_GraduateMock = _mocks.CreateMock(Of Graduate)()
_UndergraduateMock = _mocks.CreateMock(Of UnderGraduate)()
End Sub
<Test()>
Public Sub getStudentCourse()
_StudentMock.Expects.One.Method(Function(x) x.getCourse1).WillReturn("Student Course1")
End Sub
<Test()>
Public Sub getGraduateCourse()
_GraduateMock.Expects.One.Method(Function(x) x.getCourse1).WillReturn("Graduate Course1")
End Sub
<Test()>
Public Sub getUndergraduateCourse()
_UndergraduateMock.Expects.One.Method(Function(x) x.getCourse1).WillReturn("Undergraduate Course1")
End Sub
End Class
End Namespace
Public MustInherit Class Student
Public Overridable Function getCourse1() As String
Return "Student course"
End Function
End Class
Public Class Graduate
Inherits Student
Public Overrides Function getCourse1() As String
Return "Graduate course"
End Function
End Class
Public Class UnderGraduate
Inherits Student
Public Overrides Function getCourse1() As String
Return "Undergraduate course"
End Function
End Class
我错过了什么?