Private methods in C# unit testing: runtime errors and solutions
Visual Studio's ability to unit test private methods via auto-generated accessor classes may seem convenient, however, in some cases such tests can encounter runtime errors, as shown in the provided sample code. The problem stems from a difference between the type inferred by the compiler (TypeA_Accessor) and the actual runtime type (TypeA), resulting in a conversion error when adding elements to the list.
To resolve this issue, consider the following:
Alternatively, please consider the following general advice:
The above is the detailed content of Should I Unit Test Private Methods in C#, and How Can I Avoid Runtime Errors?. For more information, please follow other related articles on the PHP Chinese website!