如何将ZF2单元/应用模块测试整合为一个调用? [英] How to consolidate ZF2 unit/application module tests into a single call?

查看:81
本文介绍了如何将ZF2单元/应用模块测试整合为一个调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循将测试存储在模块中的ZF2约定,当在每个模块中运行测试时,一切工作正常.我想做的是拥有一个根目录phpunit.xml,它可以调用各个模块测试并将其合并以生成代码覆盖率数据和其他指标.

问题是每个单独的测试套件都在模块化phpunit.xml文件中引导.我知道做事的唯一方法是在每个phpunit.xml文件中配置引导程序,当从根目录运行测试时,由于忽略了单个xml文件,因此显然不会启动引导程序.

所以我的问题是:有没有一种方法可以让根级别的phpunit.xml文件从模块中读取单个phpunit.xml和引导文件,如果可以的话,这是一种phpunit config继承吗?我可以沿用Phing或CI脚本编写此代码,但是我希望它在开发过程中既快速又肮脏,并且该解决方案仍然无法生成合并的代码报告.

基本上,我想要这样的东西,但我希望它不运行测试,而是运行每个模块中的各个phpunit.xml文件.这可能吗?

<?xml version="1.0" encoding="UTF-8"?>

<phpunit>
    <testsuites>
        <testsuite name="Site Tests">
            <directory>./module/Application/test/ApplicationTest</directory>
            <directory>./module/User/test/UserTest</directory>
        </testsuite>
    </testsuites>
</phpunit>

更新

目标是使PHPUnit生成的代码度量提供项目概述,而不是模块化的特定概述.我感谢答案中的脚本将按模块运行单元测试,但这不是我想要的.我了解就PHPUnit而言,这可能是一个限制.在接下来的几天中,我将对此进行研究,并尝试找到一种解决方案,因为它似乎在许多处理自定义模块的项目中很有用.

更新2

Robert Basic提出了一个脚本,该脚本创建了一个内部包含模块报告的目录结构,虽然效果很好,但是最好在具有适当度量报告的PHPUnit中运行它.

https://gist.github.com/robertbasic/5329789

解决方案

如果您使用的是Linux,则可以创建一个简单的脚本.并非完全是您想要的解决方案,但仍然可以提供帮助:

#!/bin/sh

modDir=$(pwd)
for i in *; do

    if [[ -d $i/test ]]; then
        cd $i/test
        phpunit
        cd $modDir
    fi
done

您可以将其放入模块目录中的runtests.sh文件中.

只是一个想法:)

I'm following the ZF2 convention of storing tests in the modules and everything is working fine when tests are run from within each module. What I would like to do is have a root level phpunit.xml that calls the individual module tests and consolidates them to produce code coverage data and other metrics.

The problem is that each individual test suite is bootstrapped within the modular phpunit.xml files. The only way I'm aware of doing things is to configure the bootstrap in each phpunit.xml file which obviously doesn't get picked up when running tests from root as individual xml files are ignored.

So my question is: is there a way for a root-level phpunit.xml file to read individual phpunit.xml and bootstrap files from modules, a kind of phpunit config inheritance if you will? I could go down the route of writing this in Phing or a CI script but I'd like it done quick and dirty while in development and this solution still wouldn't produce a consolidated code report.

Basically, I want something like this, but rather than run the tests, I want it to run the individual phpunit.xml files within each module. Is this possible?

<?xml version="1.0" encoding="UTF-8"?>

<phpunit>
    <testsuites>
        <testsuite name="Site Tests">
            <directory>./module/Application/test/ApplicationTest</directory>
            <directory>./module/User/test/UserTest</directory>
        </testsuite>
    </testsuites>
</phpunit>

Update

The aim is to have code metrics generated by PHPUnit that give a project overview, not a modular specific overview. I appreciate the scripts in the answers will run the unit tests on a per-module basis but this is not what I'm looking for. I understand that this may be a limitation as far as PHPUnit is concerned. I will look into this over the next few days and try and find a solution as it seems like something that would be useful in a lot of projects that deal with custom modules.

Update 2

Robert Basic came up with a script that creates a directory structure with the module reports inside and it works great but would be nice to have it running within PHPUnit with the proper metrics reporting.

https://gist.github.com/robertbasic/5329789

解决方案

If you are using Linux you could create a simple script. Not exactly the solution you wanted, but could help none the less:

#!/bin/sh

modDir=$(pwd)
for i in *; do

    if [[ -d $i/test ]]; then
        cd $i/test
        phpunit
        cd $modDir
    fi
done

You could just drop that in to a runtests.sh file in the module directory.

Just a thought :)

这篇关于如何将ZF2单元/应用模块测试整合为一个调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆