mardi 27 juin 2017

Is it a good practice to have member functions to assert for tests in c#

While writing tests I found that assert statements to compare objects are generally placed within the tests project and not part of the actual class being checked for equality.

Was wondering if it is good practice to instead have a assert method right within the class itself like the following:

public class Person
{
     public string FirstName {get;set;}
     public string LastName {get;set;}

     public AssertEquals(Person expected)
     {
          Assert.AreEqual(expected.FirstName, FirstName);
          Assert.AreEqual(expected.LastName, LastName);
     }
}

Aucun commentaire:

Enregistrer un commentaire