Testing Private Members
Unit Testing Private Members with XUnit
Updated: 03 September 2023
Testing Private Members
In order to test the values of private members (if for some reason that’s necessary) you will need to make use of reflection. The following two functions will make it possible to access a private field
or property
Abastract Testing Class
Additionally the Testing Class can inherit from the following base abstract
And then the testing class simply needs to be defined as:
Inherited Members
A more generic version of the above is also able to test for members that are in inherited classes (which the above will fail at):