markTestSkipped()不通过Sauce Labs使用基于香肠的Selenium测试

时间:2013-07-15 22:13:15

标签: selenium phpunit automated-tests skip saucelabs

我使用sausage框架通过Sauce Labs运行基于phpunit的并行化Selenium Web驱动程序测试。一切都运行良好,直到我想通过markTestSkipped()将测试标记为跳过。我通过两种方法尝试了这个:

在测试方法本身中设置markTestSkipped():

class MyTest
{
    public function setUp()
    {
        //Some set up
        parent::setUp();
    }
    public function testMyTest()
    {
        $this->markTestSkipped('Skipping test');
    }
}

在这种情况下,测试会被跳过,但只有在执行setUp之后才会跳过,后者会为跳过的测试执行大量不必要的工作。最重要的是,phpunit不会将测试跟踪为跳过 - 实际上它根本不跟踪测试。我得到以下输出:

Running phpunit in 4 processes with <PATH_TO>/vendor/bin/phpunit

Time: <num> seconds, Memory: <mem used>

OK (0 tests, 0 assertions)

另一种方法是在setUp方法中设置markTestSkipped():

class MyTest
{
    public function setUp()
    {
        if (!shouldRunTest()) {
            $this->markTestSkipped('Skipping test');
        } else {
            parent::setUp();
        }
    }
    protected function shouldRunTest()
    {
        $shouldrun = //some checks to see if test should be run
        return $shouldrun;
    }
    public function testMyTest()
    {
        //run the test
    }
}

在这种情况下,跳过setUp,但测试仍然无法跟踪测试被跳过。 phpunit仍然返回上面的输出。有什么想法为什么phpunit在以这种方式执行时没有跟踪我跳过的测试?

1 个答案:

答案 0 :(得分:0)

目前看来,在使用paratest时,不支持记录markTestSkipped()和markTestIncomplete()会导致PHPunit。更准确地说,如果使用参数['junitLogfile'] set调用,PHPunit将不会记录调用markTestSkipped()或markTestIncomplete()的测试 - 并且paratest使用junitLogfile调用PHPunit。

有关详细信息,请参阅:https://github.com/brianium/paratest/issues/60

我想我可以在phpunit或paratest中劈开......