混合 Assert 和 Act 步骤可以吗?AAA 更像是一种指导方针而不是规则吗?还是我错过了什么?
这是我的测试:
[TestMethod]
public void CancelButtonSelected_DontCancelTwiceThenCancel_DialogCloses()
{
// Arrange
IAddAddressForm form = Substitute.For<IAddAddressForm>();
// Indicate that when Show CancelMessage is called it
// should return cancel twice (saying we want to cancel the cancel)
// then it should return ok
form.ShowCancelMessage().Returns(DialogResult.Cancel,
DialogResult.Cancel, DialogResult.OK);
AddAddressController controller = new AddAddressController(form);
AddressItem item = TestHelper.CreateAddressBob();
// Act
EnterAddressInfo(form, controller, item);
controller.CancelButtonSelected();
Assert.IsTrue(form.DialogResult == DialogResult.None);
controller.CancelButtonSelected();
Assert.IsTrue(form.DialogResult == DialogResult.None);
controller.CancelButtonSelected();
// Assert
Assert.IsTrue(form.DialogResult == DialogResult.Cancel);
}
所以我调用了一个方法 3 次。每次通话后,我想确保我们没有真正取消对话。然后在第三次调用时,应该取消对话。
这是对 AAA 语法/样式的“合法”使用吗?