Jonathan ‘Peli’ de Halleux wrote an article ‘Pex It: Testing Internal classes‘. I just want to let the world know that you also can test non-public classes with MbUnit. You need version 22.214.171.124 or higher to use this feature.
In example bellow we test IsWhite(Char) method of System.Number class inside mscorlib assembly. Using Reflector you can see that Number is an internal class and IsWhite is a private method of this class. We can test this method event if we don’t have the source code.
The Number class has only default constructor. It means we don’t need to send parameters when creating an instance.
Let’s look at another example. This time we’re going to write test for the Key and Value properties of System.Collections.KeyValuePairs class. This class is also internal. If you don’t believe me, use Reflector. KeyValuePairs class has only one constructor that takes two Object parameters.
Happy Testing :)