您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit-phpunit.xml-phpunit-logging
发布时间:2021-10-22 23:07:22编辑:雪饮阅读()
phpunit的phpunit.xml配置文件的phpunit元素的logging元素,以下就简称为logging了。
<logging> 元素
父元素:<phpunit>
<logging> 元素及其子元素可用于配置测试执行期间的日志记录。
<junit> 元素
父元素:<logging>
配置 JUnit XML 格式的测试结果日志文件。
outputFile 属性
可能值:字符串
JUnit XML 格式的测试结果日志写入的文件。
<teamcity> 元素
父元素:<logging>
配置 TeamCity 格式的测试结果日志文件。
outputFile 属性
可能值:字符串
TeamCity 格式的测试结果日志写入的文件。
<testdoxHtml> 元素
父元素:<logging>
配置 TestDox HTML 格式的测试结果日志文件。
outputFile 属性
可能值:字符串
TestDox HTML 格式的测试结果日志写入的文件。
<testdoxText> 元素
父元素:<logging>
配置 TestDox 文本格式的测试结果日志文件。
outputFile 属性
可能值:字符串
TestDox 文本格式的测试结果日志写入的文件。
<testdoxXml> 元素
父元素:<logging>
配置 TestDox XML 格式的测试结果日志文件。
outputFile 属性
可能值:字符串
TestDox XML 格式的测试结果日志写入的文件。
<text> 元素
父元素:<logging>
配置文本格式的测试结果日志文件。
outputFile 属性
可能值:字符串
文本格式的测试结果日志写入的文件。
那么一个phpunit.xml实例如:
<phpunit bootstrap="src/autoload.php">
<logging>
<junit outputFile="junit.xml"/>
<teamcity outputFile="teamcity.txt"/>
<testdoxHtml outputFile="testdox.html"/>
<testdoxText outputFile="testdox.txt"/>
<testdoxXml outputFile="testdox.xml"/>
<text outputFile="logfile.txt"/>
</logging>
</phpunit>
则测试用例进行测试运行的实例如:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe D:\phpstudy_pro\WWW\phpunitLearning\logging\phpunit-9.5.10.phar -c D:\phpstudy_pro\WWW\phpunitLearning\logging\phpunit.xml D:\phpstudy_pro\WWW\phpunitLearning\logging\tests\MyTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
.
MyTest::testOne
.
MyTest::testTwo
. 3 / 3 (100%)
MyTest::testThree
Time: 00:00.192, Memory: 22.00 MB
OK (3 tests, 3 assertions)
然后就会在phpunit.xml中所配置的这几个日志生成方式对应配置的生成日志文件(若不存在就会自动创建)中对应生成日志:
C:\Users\Administrator>dir D:\phpstudy_pro\WWW\phpunitLearning\logging
驱动器 D 中的卷没有标签。
卷的序列号是 CEDA-A76E
D:\phpstudy_pro\WWW\phpunitLearning\logging 的目录
2021/10/22 22:57 <DIR> .
2021/10/22 22:57 <DIR> ..
2021/10/22 22:57 98 .phpunit.result.cache
2021/10/22 22:57 500 command.txt
2021/10/22 22:57 1,014 junit.xml
2021/10/22 22:57 139 logfile.txt
2021/10/11 19:39 4,485,283 phpunit-9.5.10.phar
2021/10/21 13:38 328 phpunit.xml
2021/10/21 13:42 <DIR> src
2021/10/22 22:57 1,007 teamcity.txt
2021/10/22 22:57 1,088 testdox.html
2021/10/22 22:57 33 testdox.txt
2021/10/22 22:57 641 testdox.xml
2021/10/21 13:42 <DIR> tests
10 个文件 4,490,131 字节
4 个目录 152,873,852,928 可用字节
具体内容这里仅仅以第一个junit.xml为例给大家看看哈:
C:\Users\Administrator>type D:\phpstudy_pro\WWW\phpunitLearning\logging\junit.xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="MyTest" file="D:\phpstudy_pro\WWW\phpunitLearning\logging\tests\MyTest.php" tests="3" assertions="3" errors="0" warnings="0" failures="0" skipped="0" time="0.000441">
<testcase name="testOne" class="MyTest" classname="MyTest" file="D:\phpstudy_pro\WWW\phpunitLearning\logging\tests\MyTest.php" line="5" assertions="1" time="0.000209">
<system-out>
MyTest::testOne
</system-out>
</testcase>
<testcase name="testTwo" class="MyTest" classname="MyTest" file="D:\phpstudy_pro\WWW\phpunitLearning\logging\tests\MyTest.php" line="10" assertions="1" time="0.000117">
<system-out>
MyTest::testTwo
</system-out>
</testcase>
<testcase name="testThree" class="MyTest" classname="MyTest" file="D:\phpstudy_pro\WWW\phpunitLearning\logging\tests\MyTest.php" line="15" assertions="1" time="0.000114">
<system-out>
MyTest::testThree
</system-out>
</testcase>
</testsuite>
</testsuites>
这里其实也就只指定测试了MyTest.php,那么MyTest.php的测试用例类也可以让大家看看的哈:
C:\Users\Administrator>type D:\phpstudy_pro\WWW\phpunitLearning\logging\tests\MyTest.php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase
{
public function testOne(): void
{
echo "\r\n".__METHOD__."\r\n";
$this->assertTrue(true);
}
public function testTwo(): void
{
echo "\r\n".__METHOD__."\r\n";
$this->assertTrue(true);
}
public function testThree(): void
{
echo "\r\n".__METHOD__."\r\n";
$this->assertTrue(true);
}
}
关键字词:phpunit,logging
相关文章
- phpunit-phpunit.xml-phpunit-php-files
- phpunit-phpunit.xml-phpunit-testsuites-testsuite-f
- phpunit-phpunit.xml-phpunit-testsuites-testsuite-d
- phpunit-phpunit.xml-phpunit-testsuites-testsuite-d
- phpunit-phpunit.xml-phpunit-testsuites-testsuite-d
- phpunit-phpunit.xml-phpunit-testsuites-testsuite-d
- phpunit如何生成代码覆盖率?“No filter is configured
- phpunit-phpunit.xml-testsuites、testsuite
- phpunit-phpunit.xml-phpunit-testdox
- phpunit-phpunit.xml-phpunit-executionOrder