2009年10月10日星期六

Re: [fw-mvc] How to start a test?

I read the guide reference again, and get upset again. 

I want to tell you why:

I have a model class named User_Model_User under application/modules/user/models/User.php file. This class has some fucntions to manipulate user data, such as add a user, update a user. And I want to test these functions.

I build a test file: tests/application/modules/user/models/UserTest.php.

I need to include the model class file, and Zend_DB, Zend_Config, and maybe some other classes and files.

If I create a new test file, I need to include these again and again, need I?

Do we have a good way to 
        1. autoload these related classes? 
        2. load once and use anywhere at anytime?

2009/9/28 Matthew Weier O'Phinney <matthew@zend.com>
-- huajun qi <qihjun@gmail.com> wrote
(on Sunday, 27 September 2009, 10:28 AM +0800):
> I read the guide reference about testing,  and I think it's different
> from usual unit test, it is integrated into the frame, isn't it?
>
> If I just want to test a class, but it refers to database, how can I
> do it?

For normal unit testing, you can use the unit testing framework of your
choice: PHPUnit, SimpleTest, phpt, etc.

What ZF provides are some PHPUnit extensions that allow you to test your
MVC applications and/or code that utilizes Zend_Db; these are found in
Zend_Test_PHPUnit_ControllerTestCase and Zend_Test_PHPUnit_Db,
respectively

> Does the test classes zf provides need to start the application?

For MVC application testing, yes -- you need to bootstrap your
application, and then use the methods in the ControllerTestCase to
dispatch actions and test against the response.

For testing code that utilizes Zend_Db -- for instance, your models
and/or service layer -- you can either use the DatabaseTestCase or the
DB mixin support to bootstrap the database connection.

> And I prefet to use simpletest framework, can it be deployed well?

It can -- but we have no official support for it within the framework.

--
Matthew Weier O'Phinney
Project Lead            | matthew@zend.com
Zend Framework          | http://framework.zend.com/




--
Location:

没有评论: