First I’m sorry if question is already been asked but I don’t find anyone like the mine (but I assume it is a pretty common question)
So I’m trying to do some unit tests, and the first one is already problematic..
I have to test the constructor of my class, in the constructor I set an instance of a private field.. So how do I test if this PRIVATE field is not null? (because I assume is that what I have to test)–> To test :
public BUDGET_MANAGER()
{
this.budget_provider = new BUDGET_PROVIDER();
}
–> Test Mehod :
[TestMethod()]
public void BUDGET_MANAGERConstructorTest1()
{
BUDGET_MANAGER target = new BUDGET_MANAGER();
Assert.IsNotNull(??,"the provider is not instancied");
}
How Can I do that? Thanks for help, I’m pretty lost in unit testing..
In your unit testing you really shouldn’t have to test anything that’s private to a class. The private, internally-only known members are part of the implementation of the class and not part of its exposed (and tested) functionality.
Basically, think of the externally-visible members of the class as its “contract.” That defines its actual type, what everything else sees. And that is the functionality being tested. Internal (private) members aren’t known outside of the class for very good reason, a different class can implement that same “contract” (or interface) in a different way, with different private members.
What you’re testing is the visible functionality, the contract or interface.