来自不同目录的 PhpUnit 测试 [英] PhpUnit Testing from different directories

查看:43
本文介绍了来自不同目录的 PhpUnit 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 pear 在以下目录结构 C:\Easy-PHP\pear\PHPUnit 中安装了 phpunit.

I have installed phpunit in a wamp server using pear in the following directory structure C:\Easy-PHP\pear\PHPUnit.

PHPUnit 运行良好,我可以从全局运行它,即 c:\phpUnit

PHPUnit runs fine, I can run it from globally i.e. c:\phpUnit

我的问题是如何从目录中运行测试?

My question is how do I run tests from within directories?

例如:

我在 c:\Users\j.bloggs\workspace\assets\project-name\classes\myClass.php 中有要测试的类

I have classes to be tested in c:\Users\j.bloggs\workspace\assets\project-name\classes\myClass.php

我在 c:\Users\j.blogs\workspace\assets\project\tests\myClassTest.php 中有测试

I have tests in c:\Users\j.bloggs\workspace\assets\project\tests\myClassTest.php

如何设置使用 PHPUnit 以这种方式运行测试?我看过phpunit.xml和bootstrap.php的资料,我该如何实现?我没有发现任何明确的内容.

How do I set up using PHPUnit to run tests in this way? I have seen information on phpunit.xml and bootstrap.php, how do I implement these? I have not found anything clear on this.

感谢您的帮助.

推荐答案

当您从命令行运行 PHPUnit 时,它首先会在其现有目录中查找任何 phpunit.xml 文件以提供设置,如果它包含引导程序文件的路径,那么该引导程序文件将被预先执行.

When you run PHPUnit from the command line, it first looks in its existing directory for any phpunit.xml file to provide settings, and if it contains the path to a bootstrap file, then that bootstrap file will be executed beforehand.

引导文件应该能够提供要测试的类的来源(通过设置它们,如果测试文件本身没有).

The bootstrap file should be able to provide the source of the classes to be tested (by setting them up, if the test files themselves don't).

之后,它会递归地在当前工作目录中的目录中查找符合命名约定XXXTest.php的文件,然后执行它们.

After that, it recursively looks in directories in the current working directory, for files that follow the naming convention XXXTest.php, then executes them.

简单地说,只需导航到您的测试文件夹并运行 phpunit.

Simply put, just navigate to your test folders and run phpunit.

这篇关于来自不同目录的 PhpUnit 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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