您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit指明应当不覆盖任何方法的测试-@coversNothing
发布时间:2021-09-29 21:32:59编辑:雪饮阅读()
“@coversNothing 标注来指明一个测试不覆盖任何方法(参见@coversNothing)。这可以在编写集成测试时用于确保代码覆盖全部来自单元测试。”
<testsuites>
<testsuite name="Database">
<file>tests/UserTest.php</file>
<file>tests/DatabaseTest.php</file>
<file>tests/InvoiceTest.php</file>
<file>tests/GuestbookIntegrationTest.php</file>
</testsuite>
</testsuites>
<php>
<var name="DB_DSN" value="mysql:dbname=myguestbook;host=localhost" />
<var name="DB_USER" value="root" />
<var name="DB_PASSWD" value="123456" />
<var name="DB_DBNAME" value="myguestbook" />
</php>
</phpunit>
(3) flat.xml: 当然了它这里是在数据集入库后自己又新增了一条后然后才和这个flat.xml中的数据进行表状态断言的。 实际上这里以这个GuestbookIntegrationTest.php进行单独的phpunit测试或者是以组织测试,仍旧是看不出执行结果中有什么覆盖率。难道说文档中说的集成测试不是指组织测试?
<dataset>
<guestbook id="1" content="Hello buddy!" user="joe" created="2010-04-24 17:15:23" />
<guestbook id="2" content="I like it!" user="nancy" created="2010-04-26 12:14:20" />
</dataset>
<dataset>
<guestbook id="1" content="Hello buddy!" user="joe" created="2010-04-24 17:15:23" />
<guestbook id="2" content="I like it!" user="nancy" created="2010-04-26 12:14:20" />
<guestbook id="3" content="Hello world!" user="suzy" created="2010-04-26 12:14:20" />
</dataset>
use PHPUnit\DbUnit\TestCase;
final class GuestbookIntegrationTest extends TestCase
{
static private $pdo = null;
private $conn = null;
final public function getConnection()
{
if ($this->conn === null) {
if (self::$pdo == null) {
self::$pdo = new PDO( $GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD'] );
}
$this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS['DB_DBNAME']);
}
return $this->conn;
}
public function getDataSet()
{
return $this->createFlatXMLDataSet(dirname(__FILE__).'\_files\guestbook-seed.xml');
}
/**
* @coversNothing
*/
public function testAddEntry(): void
{
self::$pdo->exec("insert into guestbook(user,content,created) values('suzy','Hello world!','2010-04-26 12:14:20')");
$queryTable = $this->getConnection()->createQueryTable(
'guestbook', 'SELECT * FROM guestbook'
);
$expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__)."/flat.xml")->getTable("guestbook");
$this->assertTablesEqual($expectedTable, $queryTable);
}
}
关键字词:phpunit,coversNothing