Unit testing and checking private variable value

后端 未结 6 1699
难免孤独
难免孤独 2020-11-27 04:27

I am writing unit tests with C#, NUnit and Rhino Mocks. Here are the relevant parts of a class I am testing:

public class ClassToBeTested
{
    private IList         


        
6条回答
  •  死守一世寂寞
    2020-11-27 04:54

    I would say the "best practice" is to test something of significance with the object that is different now that it stored the entity in the list.

    In other words, what behavior is different about the class now that it stored it, and test for that behavior. The storage is an implementation detail.

    That being said, it isn't always possible to do that.

    You can use reflection if you must.

提交回复
热议问题