簡體   English   中英

如何跳過 PHPunit 中的測試?

[英]How to skip tests in PHPunit?

我將 phpunit 與 jenkins 結合使用,我想通過在 XML 文件phpunit.xml設置配置來跳過某些測試

我知道我可以在命令行上使用:

phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest

由於<filters>標簽僅用於代碼覆蓋,我該如何將其轉換為 XML 文件?

我想運行除testStuffThatAlwaysBreaks之外的所有測試

跳過損壞的測試或稍后需要繼續處理的測試的最快和最簡單的方法是將以下內容添加到單個單元測試的頂部:

$this->markTestSkipped('must be revisited.');

如果您可以忽略整個文件,那么

<?xml version="1.0" encoding="UTF-8"?>

<phpunit>

    <testsuites>
        <testsuite name="foo">
            <directory>./tests/</directory>
            <exclude>./tests/path/to/excluded/test.php</exclude>
                ^-------------
        </testsuite>
    </testsuites>

</phpunit>

有時根據定義為 php 代碼的自定義條件跳過特定文件中的所有測試很有用。 您可以使用 setUp 函數輕松地做到這一點,其中 makeTestSkipped 也可以工作。

protected function setUp()
{
    if (your_custom_condition) {
        $this->markTestSkipped('all tests in this file are invactive for this server configuration!');
    }
}

your_custom_condition可以通過一些靜態類方法/屬性、在 phpunit 引導文件中定義的常量甚至全局變量傳遞。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM