【发布时间】:2019-07-01 10:39:08
【问题描述】:
我对单元测试和 TDD 很陌生,我的疑惑是围绕我正在运行的以下测试:
class TypeTest extends TestCase
{
private $typeNameForTests = "staff";
public function setUp()
{
parent::setUp();
}
public function testMake()
{
$type = Type::make($this->typeNameForTests);
$this->assertTrue(
$type instanceof Type,
"make() should return an instance of " . Type::class
);
return $type;
}
/**
* @depends testMake
*/
public function testToString($type)
{
$this->asserTrue(
$type->__toString() == 'staff',
"make() parameter should be set as the type name"
);
}
/**
* @depends testMake
*/
public function testSetAndGetParent($type)
{
$parent = $this->createMock(Type::class);
$type->setParent($parent);
$parent === $type->getParent();
}
}
我连接前两个测试的方式可以吗? 断言方法的返回是必要的,并且在这种情况下有意义吗?
测试依赖项 (testToString) 在那里有意义吗?
那么在同一个测试中测试 Get 和 Set 怎么样?
感谢您的任何意见,因为我觉得我可能对某些原则想得过多...
谢谢!
【问题讨论】:
标签: php unit-testing phpunit tdd