PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Nov 19, 2018 3:54 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Jun 11, 2009 7:30 pm 
Offline
DevNet Evangelist

Joined: Tue Dec 21, 2004 6:00 pm
Posts: 6267
Location: Winnipeg
Say when testing a database abstraction layer, you instantiate the adapter and inject the provider (mysql, mssql, etc).

Which system is under test? Both? Does mocking the adapter make sense in BDD parlance? Does it make sense to mock either? Because one is the interface, the other the implementation, is it practical to assume they constitute the same system?


Top
 Profile  
 
PostPosted: Sun Jun 14, 2009 9:45 am 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
If you are unit testing you would test the adapter, and the abstraction class(es), each would be the SUT in their own unit test, each may reappear in the other's unit tests as DOC ( depended on component ) or may be mocked out. you would ideally have tests for your DAO that makes round trips to the database, verifies reads and writes, you'd wrap these kinds of tests in begin transaction / rollback calls so nothing commited.

I made the mistake of making my read tests too humble, that is if I go into the database and edit the record the test will fail of course because the values are no longer equal

1 - clear identity maps to force a fresh read, verify expected values returned ( write tests would be seperate )

I'm having to go back and rewrite some stuff so the flow will basically be like this

1 - begin tranaction
2 - insert expected values, clear identity maps to force a fresh read, verify expected values returned ( this way it is a round trip test )
3 - rollback

The problem with the first approach is it is too brittle towards manual testing interfering with the expected values, the second de-couples the tests from "hard coded" test data, and as long as you call rollback the unit tests wont even interfere with the "production" data


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group