【问题标题】:symfony2 unit testing console output test name or numbersymfony2 单元测试控制台输出测试名称或编号
【发布时间】:2013-02-07 15:05:06
【问题描述】:

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

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

    }

【问题讨论】:

    标签: php unit-testing symfony phpunit


    【解决方案1】:

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

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

    【讨论】:

    • 这样更好 - 它至少将范围缩小到功能。仍然希望我可以通过为每个测试分配一个名称来更进一步。 +1
    • 谢谢。我假设你所说的“测试”真的是一个断言,对吧?因为“test”是整个方法,所以test的名字和方法的名字一样。如果您想为您的断言提供名称或标签,您已经给出了如何执行此操作的示例。您只需将第三个参数传递给例如。 “assertEquals”(或在某些情况下,如“assertTrue”)到您的断言。还是我忽略了您的担忧?
    • 我正在寻找它以将“1.2 另一个测试”或我作为字符串输入到控制台的任何内容作为断言的一部分输出。感谢“--debug”,我现在有了测试函数名称。我给出的示例不起作用,它是用来描述我正在尝试做的事情。
    猜你喜欢
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    相关资源
    最近更新 更多