1
Answer

NUnit : How to prevent calling base class constructor or mocking it

Man Mundhra

Man Mundhra

1y
457
1

I am using asp.net mvc application with NUnit test project (dotnet framwork).

I am trying to test SomeController method which is inheriting from BaseController.

In BaseController , there is a parameter less constructor which read configuration, open db connection, writing logs etc.

When i do unit test of one of method in SomeController its keep calling BaseController constructor.

I wanted to mock BaseController so that its constructor not get called.

I tried mocking BaseController but not sure how the same used with SomeController as mocked base class.

The project i am working is existing one without code coverage. Now we started doing that.

How to resolve this ? Waiting for answers and alternate approach ...

Answers (1)