views:

773

answers:

6

How would design and organize tests for the concrete methods of an abstract class? Specifically in .NET.

A: 

Any reason not to just include that in the testing of one of the instances?

If that doesn't work, you could probably create a subclass just for testing with no unique functionality of its own.

Bill K
One reason may be that we're not defining the concrete classes, just the abstract. Alternatively, it's nice to know when the test fails that it's not because of one of the abstract methods.
Blair Conrad
+1  A: 

The first thing that comes to mind is to test those methods in a concrete child class.

R. Bemrose
+6  A: 

You have to create a subclass that implements the abstract methods (with empty methods), but none of the concrete ones. This subclass should be for testing only (it should never go into your production code). Just ignore the overridden abstract methods in your unit tests and concentrate on the concrete methods.

Bill the Lizard
In addition, if you end up having a lot of these (more than 2 or 3) you should consider using a mocking framework like Rhino.Mocks or Moq (free) or TypeMock (commercial) and do a "PartialMock" which will automate this process for you
chadmyers
A: 

I Always use Stub/Mock object

Daok
A: 

You have to define and create a concrete test class that inhereits from the abstract. Typically it will be a light shim that does nothing but pass through calls.

ctacke
+3  A: 

Use Rhino Mocks, it can generate implementations of the abstract class at runtime and you can call the non-abstract methods.

Ted Elliott