lundi 19 septembre 2016

Writing unit tests with omitting some methods inside a method and also some conditions on method being tested

How to write tests that escapes or bypasses few methods and conditions inside a big method that is being tested.

For example, I have this method below:

public bool IsValid(int id)
{

 var details = _myService.GetDetails(id); // This line should be avoided in test
 var doctorDetails = _myService.GetDoctorDetails("AUS"); // This needs to be executed

if(details.Name == "Ab") // This if I dont want to be part of my test
{
 // Do something

}

if(doctordetails !=null)
{
// Code to test

}
}

Aucun commentaire:

Enregistrer un commentaire