a a a是使单元测试更具可读性的准则。在你提供的例子中,我认为你没有达到这个目标。
我认为下面的测试使您正在测试的场景更具可读性。
[TestMethod]
public void CancelButtonSelected_ShouldSetDialogResultToNone_WhenFirstCancelButtonIsSelected()
{
// Arrange
IAddAddressForm form = ArrangeFormForCancelButtonSelectedTests();
AddAddressController controller = ArrangeControllerForCancelButtonSelectedTests();
// Act
controller.CancelButtonSelected();
// Assert
Assert.IsTrue(form.DialogResult == DialogResult.None);
}
[TestMethod]
public void CancelButtonSelected_ShouldSetDialogResultToNone_WhenSecondCancelButtonIsSelected()
{
// Arrange
IAddAddressForm form = ArrangeFormForCancelButtonSelectedTests();
AddAddressController controller = ArrangeControllerForCancelButtonSelectedTests();
// Act
controller.CancelButtonSelected();
controller.CancelButtonSelected();
// Assert
Assert.IsTrue(form.DialogResult == DialogResult.None);
}
[TestMethod]
public void CancelButtonSelected_ShouldSetDialogResultToCancel_WhenThirdCancelButtonIsSelected()
{
// Arrange
IAddAddressForm form = ArrangeFormForCancelButtonSelectedTests();
AddAddressController controller = ArrangeControllerForCancelButtonSelectedTests();
// Act
controller.CancelButtonSelected();
controller.CancelButtonSelected();
controller.CancelButtonSelected();
// Assert
Assert.IsTrue(form.DialogResult == DialogResult.Cancel);
}