【发布时间】:2020-01-25 00:50:27
【问题描述】:
我有一个测试套件,在我的 PHPUnit 配置中标记为 so。测试套件包含各种许多测试,并且它还具有数据库密集型实时数据库测试,这些测试需要很长时间才能完成。
特别是其中一项测试需要 2 秒以上才能完成(见下文)。
我想分开运行快速测试和慢速测试,这样当我有更多时间时,我可以运行完整的慢速但完整的测试版本,但总的来说我想运行快速测试满足我的日常需求,从而在运行测试套件时省略了缓慢的测试。
我该怎么做?
为了记录,我的 phpunit.xml 配置是这样的:
<phpunit bootstrap="bootstrap.php">
<testsuite name="Crating">
<directory>../module/Crating/test/</directory>
</testsuite>
</phpunit>
我用来运行我的测试套件的命令是这样的:
phpunit -c phpunit.xml --testsuite CratingCalc
我的../module/Crating/test/ 目录中的一个文件是CrateRepositoryTest.php。看起来是这样的:
class CrateRepositoryTest extends TestCase
{
function testCombine()
{
//mocked up hardcoded data
$fake = new FakeCratingDataModel();
//connection to real live database
$real = new CratingDataModel();
/*
* Tests that verify mocked up data to match live data
* Purpose to have them is to alert me when live database data or schema change
*/
$this->assertEquals($fake->getContentsBySalesOrderNumber(7777), $real->getContentsBySalesOrderNumber(7777));
$this->assertEquals($fake->getContentsByShopJobNumber(17167), $real->getContentsByShopJobNumber(17167));
$this->assertEquals($fake->getNearCrating(20, 20, 20), $real->getNearCrating(20, 20, 20));
$this->assertEquals($fake->getContentsByInquiryNumber(640, 2), $real->getContentsByInquiryNumber(25640, 2));
}
}
【问题讨论】:
标签: unit-testing configuration phpunit