我如何对下面这个简单的例子这样的接口进行单元测试:
interface My_App_My_Interface
{
/**
* @return int
*/
public function getInteger();
/**
* @return string
*/
public function getString();
}另外,在我的应用程序测试目录中如何组织:
tests > My > App > My > InterfaceTest ??
发布于 2012-12-08 22:38:13
您不会测试接口。您可以测试实现。如果接口提供了所有需要的功能,则应该(由人工)检查它们
发布于 2012-12-08 22:50:33
正如piotrek所说,你永远不会测试接口,因为它们只是一个契约,里面没有代码。
例如,使用atoum testing framework,您可以编写实现您的接口的类。
namespace mageekguy\atoum\tests;
class TestMyInterfaceImplementation extends atoum\test{
public function test__construct(){
$object = new MyObject();
$this->object($object)->instanceof('MyInterface');
}
public function test_getInteger(){
$object = new MyObject();
$this->integer($object->getInteger);
}
}因为接口只提供抽象的方法,所以它们不能被实例化,所以不能编写测试。
https://stackoverflow.com/questions/13778449
复制相似问题