3A 原則 – Arrange 、 Act 、 Assert
[TestMethod] public void UnitTest3ARule() { //Arrange //Act //Assert }
- Arrange – 初始化
- Act – 行為,測試對象的執行過程
- Assert – 驗證結果
範例 : 計算機 x = 10 ,y=20 執行 Add 後應該回傳 30
[TestClass] public class UnitTest1 { [TestMethod] public void UnitTest3ARule() { //Arrange var calc = new Calculator(); int x = 10, y = 20; //Act int actual = calc.Add(x, y); //Assert int expected = 30; Assert.AreEqual(expected, actual); } } public class Calculator { public int Add(int x, int y) { return x + y; } }