简体   繁体   中英

Testing Abstract Class Concrete Methods

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

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.

使用Rhino Mocks,它可以在运行时生成抽象类的实现,您可以调用非抽象方法。

首先想到的是在具体的子类中测试这些方法。

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.

我总是使用Stub / Mock对象

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM