I’m creating a unit test code for an abstract class. here is a snippet from that class:
public abstract class Component
{
private eVtCompId mComponentId;
private eLayer mLayerId;
private IF_SystemMessageHandler mLogger;
protected Component(eVtCompId inComponentId, eLayer inLayerId, IF_SystemMessageHandler inMessageHandler)
{
mLayerId = inLayerId;
mComponentId = inComponentId;
mLogger = inMessageHandler;
}
What I have in the constructor’s parameters are two enums followed by an interface.
Here is a snippet from my unit test code:
Component_Accessor target = new Component_Accessor(eVtCompId.MasterSWCommDevice, eLayer.Foundation, new MySysMsgHandler());
I keep getting the error message “Component_Accessor does not contain a constructor that takes ‘3’ arguments”. I can’t seem to understand why that is happening. When I removed the abstract keyword, the unit test works fine.
I don’t get why the unit test can’t seem to “see” the constructor if the class is set to abstract. Can anyone explain why this is happening? Thanks in advance.
You cannot create an instance of an
abstractclass.protectedconstructors are visible only for derived classes. Read Accessibility Levels (C# Reference) to clear up differences among access modifiers and their influence in various (including class) scopes.From MSDN:
Besides,
ComponentandComponent_Accessorare definitely different types.