我需要测试使用 PHP 5 创建的许多函数,这些函数执行我的 Web 应用程序所需的数据库 CRUD 类型操作(SELECT、UPDATE、INSERT、DELETE)。
我一直在研究 PHP 单元测试套件,例如 Simple Test 和 PHP Unit,它们似乎提供了我需要的东西,但是我不确定我打算如何实现这一点,因为等价分区和边界分析并不是那么清楚。我是否只需要输入不同的变量并改变它?这似乎毫无意义,因为不同的字符串不一定会有任何区别。
任何有关这方面的指导都会有所帮助,因为我以前从未遇到过这种情况。
我已经开始对我的PHP程序使用单元测试,并认为Simpletest是一个很好的潜水地点.我将Simpletest文件添加到我的测试服务器,并在我的自定义PDO类上运行以下测试:
<?php
require_once('../simpletest/autorun.php');
require_once('../includes/inc_sql.php');
class TestOfSQL extends UnitTestCase{
function testRead(){
...
}
function testWriteAndDelete(){
...
}
}
?>
Run Code Online (Sandbox Code Playgroud)
这一切都很糟糕.我尝试构建一个涉及(到目前为止)测试文件的测试套件,如下所示:
<?php
require_once('../simpletest/autorun.php');
class AllTests extends TestSuite {
function __construct(){
parent::__construct();
$this->addFile('inc_sql_test.php');
}
}
Run Code Online (Sandbox Code Playgroud)
这会崩溃并烧伤,我得到以下读数:
Warning: include_once(inc_sql_test.php) [function.include-once]: failed to open stream: No such file or directory in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 382
Warning: include_once() [function.include]: Failed opening 'inc_sql_test.php' for inclusion (include_path='.;E:\xampp\php\PEAR') in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 382
Warning: file_get_contents(inc_sql_test.php) [function.file-get-contents]: failed to open stream: No such file or directory in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line …Run Code Online (Sandbox Code Playgroud) 我正在使用Eclipse 3.4.2并使用帮助>软件更新安装最新的插件以进行简单测试...
插件安装正确,我可以在Window> Preferences> SimpleTest中进行设置.我填写了以下字段:Php.exe文件,php.ini文件和测试文件后缀.我无法找到最简单的路径(甚至在Eclipse插件文件夹中也没有).
我认为这个配置是正确的,并在最简单的eclipse网站上运行了第一个测试:http://simpletest.sourceforge.net/en/extension_eclipse.html
<?php
class test1 extends UnitTestCase {
function test_pass(){
$x = 1;
$y = 2;
$total = $x + $y;
$this->assertEqual(3,$total, "This should pass");
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我一直在遵循所有说明,但当我右键单击并选择RUN AS> SimpleTest时,没有任何反应.
我需要一些帮助.
谢谢!
我正在使用cakePHP并使用Simpletest作为测试套件.每当我在模型上运行测试时,我都会收到错误:
Missing Database Table
Error: Database table account_types for model AccountType was not found."
Run Code Online (Sandbox Code Playgroud)
(无论如何)
有谁知道如何解决这个问题?
我的猜测是没有创建灯具或沿着这些线条.
标题基本概括了所有内容.我想测试例如UsersController::admin_index()动作,但是需要授权用户访问此位置,因此当我运行测试时它会将我发送到登录页面,即使我手动登录,也没有进行任何测试.
那么如何在不编辑实际授权代码的情况下强制蛋糕跳过授权?
顺便说一句,如果有帮助,我的testAdminIndex()代码看起来像这样:
function testAdminIndex() {
$result = $this->testAction('/admin/users/index');
debug($result);
}
Run Code Online (Sandbox Code Playgroud) Netbeans哪一个更好:PHPUnit或SimpleTest?
我是PHP SimpleTest框架的新手,我很惊讶地看到失败的断言不会停止测试方法.换句话说,这会在测试报告中导致两条失败消息:
function testFoo() {
$this->assertTrue(true, 'first: %s');
$this->assertTrue(false, 'second: %s');
$this->assertTrue(false, 'third: %s');
}
Run Code Online (Sandbox Code Playgroud)
我的大部分单元测试经验都是使用JUnit和NUnit,并且一旦第一个断言失败,它们都会暂停测试方法.也许我已经习惯了,但似乎额外的失败信息只是噪音.它让我想起旧的C编译器因为缺少分号而会出现50个错误.
我可以将SimpleTest配置为快速失败,还是只需要使用不同的样式?
我最近听到很多人争论使用PHP测试功能,如PHPunit和SimpleTest以及他们选择的IDE(Eclipse for me).在谷歌搜索主题后,我仍然很难理解使用这些测试框架来加速开发的利弊.
如果有人能够在更基本的层面上为我解释这一点,我会非常感激.我正在使用PHP5作为通知.
非常感谢!
我尝试使用SimpleTest for PHP运行一些简单的测试时遇到错误.
目前,我正在根据文档扩展UnitTestCase类.我正试图在一个方法中测试我班级的不同方面.这是我的班级:
<?php
class SimpleClass extends UnitTestCase {
public function __construct() {
$this->test();
}
private function test() {
$x = true;
$this->assertTrue($x, 'x is true');
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试扩展TestSuite类并使用文档中的语法,但我得到了同样的错误:
Fatal error: Call to a member function getDumper() on a non-object in /simpletest/test_case.php on line 316
Run Code Online (Sandbox Code Playgroud)
关于我如何做到这一点的任何想法,还是我接近课堂测试错误?
php ×9
simpletest ×9
unit-testing ×8
phpunit ×3
cakephp ×1
cakephp-1.3 ×1
eclipse ×1
mysql ×1
netbeans ×1
tdd ×1