symfony2 unit测试控制台输出测试名称或编号

时间:2013-02-07 15:05:06

标签: php unit-testing symfony phpunit

我想知道我是否可以为单元测试分配名称,以便显示为其运行。因此,如果我有多个测试,所有运行失败的名称都可以很快找到

所以添加类似的东西(为了描述目的,这不是真正的代码)。其标有1​​.1和1.2的部件即将在控制台中输出

$this->assertEquals(1, 
   $crawler->filter('h1:contains("About symblog")')->count(), 
  '1.1 Test one some description'
);


$this->assertEquals(1, 
  $crawler->filter('h2:contains("' . $blogTitle .'")')->count(), 
  '1.2 Another test'
);

我不知道该怎么做。 实际代码

    public function testIndex()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/blogger/');

        // Check there are some blog entries on the page
        $this->assertTrue($crawler->filter('article.blog')->count() > 0);


        // Find the first link, get the title, ensure this is loaded on the next page
        $blogLink   = $crawler->filter('article.blog h2 a')->first();
        $blogTitle  = $blogLink->text();
        $crawler    = $client->click($blogLink->link());

        // Check the h2 has the blog title in it
        $this->assertEquals(1, $crawler->filter('h2:contains("' . $blogTitle .'")')->count());

    }

phpUnit output example

1 个答案:

答案 0 :(得分:2)

只需使用--debug这样的标志:

phpunit -c app --debug path/to/your/tests