PHPUnit TDD,PHP致命错误:调用未定义的方法 [英] PHPUnit TDD, PHP Fatal error: Call to undefined method

查看:84
本文介绍了PHPUnit TDD,PHP致命错误:调用未定义的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPUnit启动TDD项目,这确实使我感到烦恼.

I'm starting a TDD project using PHPUnit and something really bugs me.

似乎只要所有类和方法都无法实现,就无法运行所有测试. 如果尚未实现类或方法,如何使测试继续事件?

It seem that all test can't be run as long as all classes and methods will not be implemented. How can I do to make the test continue event if a class or a method is not yet implemented ?

谢谢.

"TDD的意思是您的测试套件在编写测试时失败了吗?" 是的,当然可以,但是我希望对该项目具有全球视野. 假设我们已经编写了1000个测试,并且运行的第一个测试会导致致命错误. 但是幸运的是,当我们实现代码时,该部分将是最后要实现的部分之一.我不想发展盲目"功能,只有在所有致命错误都将被清除时才能够运行我的测试套件.

"Isn't the point of TDD that your testsuite fails while writing tests?" Yes, of course, but I want to have a global sight of the project. Let say we've written 1000 test, and the first one that is run makes a fatal error. But not lucky we are, when we come to implement the code, that part will be one of the last to be implemented. I don't want to develop "blind" and only been able to run my test suites when all fatal error will be cleared.

是的,由于在此状态下正常的致命错误,测试失败与整个测试过程停止/死亡之间存在巨大差异.

So yes, their's a huge difference between a test that fail, and the whole testing process to halt/die because of a fatal error that is normal at this state.

作为一个工作环境,我们在开始编写测试之前创建了我们的类框架.

As a work-arround, we created our class skeleton before beginning to write our tests.

推荐答案

难道TDD的意思是您的测试套件在编写测试时失败了吗?

Isn't the point of TDD that your testsuite fails while writing tests?

我想您的意思是,它死于致命错误,而不仅仅是显示红色的我失败"栏.很有趣的一点是,我正在用phpunit进行TDD,但这从来没有困扰过我.

I guess your point is that it dies with a fatal error instead of just display the red "i failed" bar. Quite an interesting point, I'm doing TDD with phpunit but that never has bugged me at all.

首先想到的是--process-isolation.

让我们假设一个测试类如下:

Let's assume a test class that looks like this:

<?php

class fooTest extends PHPUnit_Framework_TestCase {

    public function testA() {
        $x = new a();
    }

    public function testB() {
        $this->assertTrue(true);
    }
}


使用普通跑步者phpunit test.php:

PHPUnit 3.5.12 by Sebastian Bergmann.

Fatal error: Class 'a' not found in /home/mcsvnls/mep.php on line 6


,但是使用phpunit --process-isolation test.php开关时,它看起来像这样:


but when using the phpunit --process-isolation test.php switch it looks like this:

PHPUnit 3.5.12 by Sebastian Bergmann.

E.

Time: 1 second, Memory: 3.25Mb

There was 1 error:

1) fooTest::testA
RuntimeException: Fatal error: Class 'a' not found in /home/foo/mep.php on line 6

Call Stack:
    0.0005     102364   1. {main}() /home/foo/-:0
    0.0341    1768644   2. __phpunit_run_isolated_test() /home/foo/-:143
    [...........]

FAILURES!
Tests: 2, Assertions: 1, Errors: 1.


现在第二个测试已执行并通过

这篇关于PHPUnit TDD,PHP致命错误:调用未定义的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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