Tengo una prueba de unidad llamada TestMakeAValidCall()
. Prueba la aplicación de mi teléfono haciendo una llamada válida.Pruebas unitarias: ¿Es malo tener llamadas de prueba unitaria a otras pruebas de unidad?
Estoy a punto de escribir otra prueba llamada TestShowCallMessage()
que debe tener una llamada válida para la prueba. ¿Es malo simplemente llamar al TestMakeAValidCall()
en esa prueba?
Como referencia esta es mi prueba TestMakeAValidCall()
.
[TestMethod]
public void TestMakeAValidCall()
{
//Arrange
phone.InCall = false;
phone.CurrentNumber = "";
// Stub the call to the database
data.Expect(x => x.GetWhiteListData()).
Return(FillTestObjects.GetSingleEntryWhiteList());
// Get some bogus data
string phoneNumber = FillTestObjects.GetSingleEntryWhiteList().
First().PhoneNumber;
// Stub th call to MakeCall() so that it looks as if a call was made.
phone.Expect(x => x.MakeCall(phoneNumber)).
WhenCalled(invocation =>
{
phone.CurrentNumber = phoneNumber;
phone.InCall = true;
});
//Act
// Select the phone number
deviceControlForm.SelectedNumber = phoneNumber;
// Press the call button to make a call.
deviceMediator.CallButtonPressed();
//Assert
Assert.IsTrue(phone.InCall);
Assert.IsTrue(phone.CurrentNumber == phoneNumber);
}
Gracias por todas las excelentes respuestas. Refactoreé el código duplicado en una llamada separada. Escogí la respuesta con la mayoría de los votos. – Vaccano