How to start a test?

6 messages Options
Embed this post
Permalink
huajun qi

How to start a test?

Reply Threaded More More options
Print post
Permalink
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?

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

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

--
Location:
weierophinney

Re: How to start a test?

Reply Threaded More More options
Print post
Permalink
-- huajun qi <[hidden email]> 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            | [hidden email]
Zend Framework          | http://framework.zend.com/
huajun qi

Re: How to start a test?

Reply Threaded More More options
Print post
Permalink
Thanks for your reply.

If I want to start a mvc testing, how can i bootstrap the application?

2009/9/28 Matthew Weier O'Phinney <[hidden email]>
-- huajun qi <[hidden email]> 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            | [hidden email]
Zend Framework          | http://framework.zend.com/




--
Location:
huajun qi

Re: How to start a test?

Reply Threaded More More options
Print post
Permalink
In reply to this post by weierophinney
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 <[hidden email]>
-- huajun qi <[hidden email]> 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            | [hidden email]
Zend Framework          | http://framework.zend.com/




--
Location:
dmitrybelyakov

Re: How to start a test?

Reply Threaded More More options
Print post
Permalink
In reply to this post by huajun qi

huajun qi wrote:
Thanks for your reply.
If I want to start a mvc testing, how can i bootstrap the application?
Usually you bootstrap your testing environment the same way as you bootstrap your application. Except for the little change in paths to your application and library folders. And yes autoloading should be available after that!

Here's a nice video walkthrough how to quickly set up scaffolding for running your unit tests:
http://www.zendcasts.com/unit-testing-with-the-zend-framework-with-zend_test-and-phpunit/2009/06/

Hope that helps,
Good luck.
huajun qi

Re: How to start a test?

Reply Threaded More More options
Print post
Permalink
Thanks!

I have watched the video, that's what I need. I think I have know how to do it now!