Does this Unit Test for a TableGateway class make sense?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Does this Unit Test for a TableGateway class make sense?

Ralf Eggert
Hi,

I have the following unit test, which uses quite some mocked objects to
test a method of a CustomerTable which extends TableGateway.

http://pastebin.com/d1try7YZ

This is the CustomerTable with its fetchList() method that should be
tested by the unit test.

http://pastebin.com/qT2P7GuD

The unit test runs through without any error and it looks like the stuff
is working as expected. But is it really? I could almost do anything
within my fetchList() method as long as it calls the selectWith() or
select() methods. I could add some order or where stuff to the select
and the test will always succeed.

So, does this Unit Test for the CustomerTable really make sense?

Any thoughts?

Thanks and best regards,

Ralf

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Does this Unit Test for a TableGateway class make sense?

franz de leon
sounds like you are looking more of an integration test and data fixtures.


On Thu, Oct 24, 2013 at 8:16 AM, Ralf Eggert <[hidden email]> wrote:

> Hi,
>
> I have the following unit test, which uses quite some mocked objects to
> test a method of a CustomerTable which extends TableGateway.
>
> http://pastebin.com/d1try7YZ
>
> This is the CustomerTable with its fetchList() method that should be
> tested by the unit test.
>
> http://pastebin.com/qT2P7GuD
>
> The unit test runs through without any error and it looks like the stuff
> is working as expected. But is it really? I could almost do anything
> within my fetchList() method as long as it calls the selectWith() or
> select() methods. I could add some order or where stuff to the select
> and the test will always succeed.
>
> So, does this Unit Test for the CustomerTable really make sense?
>
> Any thoughts?
>
> Thanks and best regards,
>
> Ralf
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Does this Unit Test for a TableGateway class make sense?

Ralf Eggert
Hi Franz,

franz de leon schrieb am 24.10.2013 15:35:
> sounds like you are looking more of an integration test and data fixtures.

Ok, need to look into that. By the way, I got my inspiration from this
little tutorial which has a quite different setup. In the tutorial the
AlbumTable uses a TableGateway instance while my CustomerTable extends
the TableGateway.

http://zf2.readthedocs.org/en/latest/tutorials/unittesting.html#testing-model-tables

So, isn't the tutorial a bit misleading in how to write proper tests?

Thanks and best regards,

Ralf

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Does this Unit Test for a TableGateway class make sense?

franz de leon
Hey Ralf,

I don't think its misleading. For unit test purposes and i emphasize the
"unit" it serves the purpose of the mocked object, the TableGateway in this
case.
It really all depends on what you are trying to accomplish. If you just
want to unit test your single method then you should be fine with your
solution above.
Integration and functional test is another layer on top of unit test to
make sure everything work as intended.


On Thu, Oct 24, 2013 at 10:30 AM, Ralf Eggert <[hidden email]> wrote:

> Hi Franz,
>
> franz de leon schrieb am 24.10.2013 15:35:
> > sounds like you are looking more of an integration test and data
> fixtures.
>
> Ok, need to look into that. By the way, I got my inspiration from this
> little tutorial which has a quite different setup. In the tutorial the
> AlbumTable uses a TableGateway instance while my CustomerTable extends
> the TableGateway.
>
>
> http://zf2.readthedocs.org/en/latest/tutorials/unittesting.html#testing-model-tables
>
> So, isn't the tutorial a bit misleading in how to write proper tests?
>
> Thanks and best regards,
>
> Ralf
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Does this Unit Test for a TableGateway class make sense?

Ralf Eggert
Hi Franz,

thanks for your reply.

> I don't think its misleading. For unit test purposes and i emphasize the
> "unit" it serves the purpose of the mocked object, the TableGateway in this
> case.
> It really all depends on what you are trying to accomplish. If you just
> want to unit test your single method then you should be fine with your
> solution above.
> Integration and functional test is another layer on top of unit test to
> make sure everything work as intended.

So, a Unit Test for a TableGateway class would only test, that my
fetchList() method is returning a ResultSet class, while an integration
test will check, that the ResultSet really returns the expected data
within the ResultSet?

But from the TDD point of view, I will need a Unit Test to check the API
and the expected objects and an Integration Test (based on
PHPUnit_Extensions_Database_TestCase for example) to check stuff like
sorting and getting the correct results.

Is that correct?

Thanks and best regards,

Ralf

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Does this Unit Test for a TableGateway class make sense?

franz de leon
Yes.


On Thu, Oct 24, 2013 at 11:16 AM, Ralf Eggert <[hidden email]> wrote:

> Hi Franz,
>
> thanks for your reply.
>
> > I don't think its misleading. For unit test purposes and i emphasize the
> > "unit" it serves the purpose of the mocked object, the TableGateway in
> this
> > case.
> > It really all depends on what you are trying to accomplish. If you just
> > want to unit test your single method then you should be fine with your
> > solution above.
> > Integration and functional test is another layer on top of unit test to
> > make sure everything work as intended.
>
> So, a Unit Test for a TableGateway class would only test, that my
> fetchList() method is returning a ResultSet class, while an integration
> test will check, that the ResultSet really returns the expected data
> within the ResultSet?
>
> But from the TDD point of view, I will need a Unit Test to check the API
> and the expected objects and an Integration Test (based on
> PHPUnit_Extensions_Database_TestCase for example) to check stuff like
> sorting and getting the correct results.
>
> Is that correct?
>
> Thanks and best regards,
>
> Ralf
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>