lirik44 / phpunit-teamcity-extended
扩展对phpunit在php标准输出中testMetadata的支持
v1.0.3
2023-12-03 09:51 UTC
Requires
- php: ^7.1|^8.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-03 11:34:37 UTC
README
扩展对PHPUnit标准输出中testMetadata的支持。
添加了Description Trait以解析测试中的@description注解
安装
composer require lirik44/phpunit-teamcity-extended
使用Descripton trait
在测试函数之前指定@description注解
class MyTest extends PHPUnit\Framework\TestCase { /** * @description This test check something on page */ public function testSomethingOnPage() { // test something ... }
在Selenium Helper中使用DescriptionTrait
class SeleniumHelper extends TestCase { protected $testHelper; public function setUp():void { $testName=$this->getName(); $this->testHelper->setupSeleniumSession($testName); date_default_timezone_set( 'Europe/Moscow' ); } use DescriptionTrait; public function tearDown():void { //If test fails get description from @description if ($this->hasFailed()) { //Get description text $this->description = $this->getTestDescription(); }
其他testMetadata特性
与描述类似,你还可以在tearDown()部分指定不同的testMetadata
public function tearDown():void { //Take metaData if test has failed if ($this->hasFailed()) { //Get browser URL in the moment of test error occur $this->browserLink = $this->webDriver->getCurrentURL(); //Get browser screenshot in the moment of test error occur $this->screenshotErr = $this->testHelper->getErrorScreenshot($testName); //Get php_errors.log after test fails $this->errLog = $this->testHelper->getPhpErrorLog($testName); //Get mono.log after test fails $this->monoLog = $this->testHelper->getMonoLog($testName); } }
此外,你还可以将任何信息放入setUp()部分,并将其作为buildTag发布
public function setUp():void { $testName=$this->getName(); $this->testHelper->setupSeleniumSession($testName); date_default_timezone_set( 'Europe/Moscow' ); //Get current application git branch $this->buildTag = $this->getUsedBranch(); }