c# - What is the name of the pattern? -


I often design the system where I have a class in my system that contains a set of protected methods. The protected methods are that because they should be accessible to specializations, and in this way, I consider the protected methods to be an agreement between my general class and a particular class.

So I want to test that these methods behave properly, so my unit tests will need to reach protected methods, something that is not possible in C #, except its Using Reflection like that dirty hacks.

The solution I usually choose is that I will create a special class within my unit test which publicly exposes these protected methods because I always keep the unit test in a separate assembly, the system These sections do not have access to the code, and inside my system code, the safe function remains secure. System Code assembly in the name system MySystem {public class SomeClass {protected void DoSomething ()} {...}}} / in the unit test assembly namespace MySystem.Unittests {public class SomeClass2: SomeClass {New Public DoSomething () {base.DoSomething (); }}}

My unit testing is now able to test the behavior of the protected member immediately on the parent class by providing special class immediately.

I also use it to be able to duplicate objects and fake panel calls for further virtual tasks, but this code is a bit more complex, so I will only cut it.

I find this method of accomplishing this task to be so straight forward that I can not possibly be the only person to do this, and therefore I feel that this is a common naming Should the conference be?

I only did this when I did not control the class required to test. Charles explains what you can do on the net when you control the source code.

Your case is slightly different because your class is intended to be used as a superclass, so it is to test through subclass. Many emotions (Since the class is standing on its own Is not intended) In this case, you are basically doing one kind. The pattern described in the link is more about overriding behavior, and if you have a class that has not been tested before and has a high coupling, then it is a good way to separate dependencies (usually an intermediate step As a parameter, passing a different class is passing) In your case, "overriding" is for the purpose, if reach grows, but it seems that it is fit in the same pattern.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -