使用計算機練習測試
1 + 2 = 3
Interface 要每個 Function 都要 Implements就比較麻煩一點 :
Public Interface ICalculator Function Add(ByVal first As Int32, ByVal second As Int32) End Interface
Public Class Calculator Implements ICalculator Public Function Add(ByVal first As Int32, ByVal second As Int32) Implements ICalculator.Add Return first + second End Function End Class
測試部分 :
<TestClass()> Public Class VbCalculatorTests <TestMethod()> Public Sub AddTest_1_And_2_ShouldBe_3() 'Arrange Dim first = 1, second = 2 Dim calc = New Calculator 'Act Dim actual = calc.Add(first, second) 'Assert Dim expected = 3 Assert.AreEqual(expected, actual) End Sub End Class