2013-02-07 51 views
2

我想知道是否可以将名称指定给单元测试,以便将其显示为其运行。因此,如果我有多个测试,所有运行失败的名称可以很快找到symfony2单元测试控制台输出测试名称或编号

因此,添加类似的东西(这不是真正的代码,下面为了描述的目的)。它的标记为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

回答

2

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

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

是更好 - 它至少缩小下来的功能。仍然希望我可以进一步分配每个测试的名称。 +1 –

+0

谢谢。我认为通过“测试”你确实是一个断言,对吧?因为“测试”是整个方法,所以测试的名称与方法的名称相同。如果你想为你的断言提供名称或标签,你已经举了一个例子来说明如何做到这一点。你只要传递第三个参数给eg。在断言中“assertEquals”(或者在某些情况下,如assertTrue)。或者我可能错过了你的担忧? – Cyprian

+0

我正在寻找它输出'1.2另一个测试'或任何我作为一个字符串输入到控制台作为断言的一部分。感谢“--debug”,我现在拥有测试函数名称。我给出的例子不起作用,它被用来描述我想要做的事情。 –