Does anybody possess some good hints for writing test code for database-after sales development where there's huge reliance upon condition?

Particularly, I wish to write tests for code that retrieve records in the database, however the solutions will rely on the information within the database (which might change with time).

Do people usually create a separate development system having a 'frozen' database to ensure that a function must always return the identical result set?

I'm quite sure this isn't a brand new problem, and so i could be very interested to understand using their company individuals experience.

Exist good articles available that discuss this problem of web-based rise in general?

It's my job to write PHP code, however i would expect many of these issues are largely language and framework agnostic.

You need to consider DBUnit, or try to look for a PHP equivalent (there has to be one available). Technology-not only to organize the database having a specific group of data which signifies your test data, and therefore each test will no more rely on the database plus some existing condition. By doing this, each test is all-in-one and won't break throughout further database usage.

Update: A fast search demonstrated a DB unit extension for PHPUnit.

If you are mostly worried about data layer testing, you might like to read this book: xUnit Test Designs: Refactoring Test Code. I had been always unsure about this myself, but this book does a fantastic job to assist enumerate the concerns like performance, reproducibility, etc.

We make use of an in-memory database (hsql : http://hsqldb.org/). Hibernate (http://www.hibernate.org/) causes it to be simple for us to suggest our unit tests in the testing db, using the added bonus they run as quick as lightning..

I've the identical trouble with my work and that i discover that the very best idea is to possess a PHP script to re-produce the database after which a seperate script where I throw crazy data in internet marketing to ascertain if it breaks it.

I haven't ever used any Unit testing or suchlike so cannot say whether it works or otherwise sorry.

If you're able to setup the database having a known quantity just before running the tests and destroy in the finish, then you will understand what data you're dealing with.

You'll be able to use something similar to Selenium to simply test out of your UI (presuming web-based here, but you will find lots of UI testing tools available for other UI-flavours) and identify the existence of certain records drawn back in the database.

It's certainly worth establishing whether test version from the database - or build your test scripts populate the database with known data included in the tests.

You could attempt http://selenium.openqa.org/ it's more for GUI testing as opposed to a data layer testing application but does record how you behave which in turn could be performed to automate tests across different platforms.

I suppose it is dependent what database you are using, but Red-colored Gate (www.red-gate.com) create a tool known as SQL Data Generator. This is often set up to fill your database with sensible searching test data. You may also tell it to continually make use of the same seed in the random number generator so that your 'random' data is identical each time.

After that you can write your unit tests to take advantage of the reliable, repeatable data.

For testing the net aspect, I am presently considering Selenium (selenium.openqa.org). This seems to become a mix-browser capable test suite which supports you test functionality. However, as with every of those site test tools, there is no real method to test how good this stuff look in most from the browsers without casting an individual eye them over!