编程语言
首页 > 编程语言> > php – 多次测试在phing中发生冲突

php – 多次测试在phing中发生冲突

作者:互联网

我们有一个Phing脚本,Hudson使用它来构建/测试我们的PHP站点.

我们的一些单元测试加载了主函数库;其他人使用模拟来避免必须这样做(或为测试提供特定的伪造结果).

当单独运行时(即在命令行上,使用phpunit),单元测试所有运行完美.但是,当我们在Phing中将它们作为批处理一起运行时,我们会收到错误.

错误发生在测试中,我们为某些函数编写了模拟函数.错误说我们两次声明该函数.它显然试图包括真正的函数库以及模拟.

测试包括互斥的代码,因此它们需要彼此隔离运行; Phing似乎只是在一个进程中运行它们,所以包含冲突.

phing脚本的相关部分如下所示:

<phpunit haltonfailure="true" printsummary="true">
  <batchtest>
    <fileset dir="${ws}/path/to/site/root/">
      <include name="*Test.php" />
      <include name="*/*Test.php" />
      <include name="*/*/*Test.php" />
      <include name="*/*/*/*Test.php" />
    </fileset>
  </batchtest>
  <formatter type="xml" todir="${builddir}/logs" outfile="units.xml" />
</phpunit>

有没有办法让phing独立地运行测试,而不是在构建脚本中单独指定每个测试?

解决方法:

那么最简单/最快速的解决方法似乎是“不要使用phing任务,而是开始使用’真正的’phpunit输出.

所以运行< exec command =“phpunit ...”> […]

并使用–coverage-html并在hudson中发布并使用–coverage-clover和junit开关将覆盖信息转换为hudson. (见jenkins-php.orgSetting up jenkins for php projects (there is a demo phpunit.xml.dist)供参考)

但是你可能不希望这样:/

据说from the Phing docs of the phpunit task我认为没有办法直接告诉phing使用–process-isolation switch.

所以也许其他人有解决方案.我没有一个仍然会产生代码覆盖率的.

从评论

我将假设您有两个单独的测试代码,无法在一个进程中运行,所以如果你能说:

run 2 processes: "testsuite one do that, testsuite two do the other thing"
after that aggregate the results

可悲的是,我不知道你怎么能告诉phpunit这样做.我将进一步调查,但目前我知道唯一可行的方法是在整个测试套件中使用–process-isolation每个测试.如果有办法在一个单独的过程中运行整个套件,我不知道它.

希望其他人有一个更简单的解决方案:)

标签:php,unit-testing,phpunit,phing
来源: https://codeday.me/bug/20190710/1420295.html