How do you unit test an interface?

后端 未结 5 1701
忘掉有多难
忘掉有多难 2020-12-13 13:37

For example, there is a interface IMyInterface, and three classes support this interface:

class A : IMyInterface
{
}

class B : IMyInterface
{
}         


        
5条回答
  •  春和景丽
    2020-12-13 14:31

    To test an interface with common tests regardless of implementation, you can use an abstract test case, and then create concrete instances of the test case for each implementation of the interface.

    The abstract (base) test case performs the implementation-neutral tests (i.e. verify the interface contract) while the concrete tests take care of instantiating the object to test, and perform any implementation-specific tests.

提交回复
热议问题