views:

858

answers:

8

I'm curious to see how other developers go about testing their web sites (PHP specifically in my case, but this probably spans multiple languages)? I've been working on a site for over a year now and I'd really like to automate a lot of the regression testing I do between versions.

This specific site is in code igniter, an MVC framework, so I have some tests for my models but I'd like to move beyond just testing those. However this is an issue even non-MVC developers have had to tackle I'm sure.

Edit: I think the functionality that would satisfy a lot of my test desires is the ability to assert that variables have a specific value at the end of the script processing. In my case a lot of logic is in the controller and that's the main area I'd like to test.

+1  A: 

You might want to check out PHPUnit http://www.phpunit.de/manual/current/en/

I have started using it on my PHP projects and it's very easy to work with and very powerful. In particular, learn and use mocks: http://www.phpunit.de/manual/3.0/en/mock-objects.html

Mocking is especially important when unit testing applications that do database operations.

OverloadUT
+8  A: 
ryeguy
Model? That's strange. Most of functionality (program logic) in my MVC applications is in Controller. Model is just a simple wrapper used to push/pull data to storage (database or whatever).
Milan Babuškov
@Milan It depends on your language and your coding style. Ruby, for example, prefers light controllers and heavy models.
ryeguy
+2  A: 

Have you tried Fitnesse ?

It helps on creating Acceptance tests. They are specially useful for websites, which doing this kind of tests are a pain.

There are a couple of videos from unclebob inside the webpage too. The good thing is that Fitnesse is not restricted for website testing, so your knowledge about using it can be used with other apps too.

The project I'm working on is a Desktop APP written in c++ that uses Fitnesse tests.

But if you meant unit testing the models (which I think you didn't), they can be create using the phpunit lib. I think the ZEND framework has a similar lib for that.

Edison Gustavo Muenz
For web apps there are a number of fixtures built to work with selenium for testing the UI in fitnesse
Jeffrey Cameron
A: 

One of the best ideas I've heard of, as far as testing web apps go, was to create a script that would go over all the pages in the site and check them for differences from the previous scan, letting you accept changes and fix regressions.

Generally speaking, automatic testing of GUI applications (websites are GUI apps) is difficult and usually unnecessary. Unit tests work best with simple libraries.

Pies
This isn't Unit Testing. Anything more than the most basic web apps will be built with multiple layers of abstraction. These should be tested in the same way any library is. If you're not familiar with OOD, maybe refrain from offering advice about it? No offense, natch.
Encoderer
The OP didn't ask about unit testing, but about testing a web application in general. I'm familiar with OOD, and I think I know what a unit test is.
Pies
Have you actually tried using unit tests in a web app? Extensive automatic testing can be a liability when applied to a real web app that changes over time. But you wouldn't know that. No offense ofc.
Pies
A: 

I use Canoo WebTest. It is the best free web site unit test framework out there. It is entirely scriptable with XML and requires no browser so it can run from a build server.

Otávio Décio
A: 

We modified Waiter (Ruby). It plays back "scripts" of URLs and Form Filling to IE and we have added a script "command" to take a Screen Capture; the screen capture image is compared against a Known-Good-Image (i.e. a Master Image) and if that image is different it is logged (basically a Web page of such results is prepared) and "a human" does a review of the Master / Test image. Obviously there are two outcomes at that point - "The difference is intentional" or "There is an incorrect change". In the first instance the Master image is replaced with the New Image; in the second we go fix the bug, and the change will be included in the next test run

Kristen
Wouldn't it be easier to compare the HTML? Unless you're also testing your Javascripts etc.
Pies
its a regression test for visual changes to site - CSS changes, in INCLUDE files, might change the presentation - and Images might have changed. We allow MASKS on the captures (e.g. where Date/Time shows) which might be harder to do in HTML compare. Our Image compare highlights areas of change
Kristen
A: 

You might want to try "Windmill". It seems to be somehow better than Selenium.

Martin Burger
+1  A: 

Take a look at TOAST. It's build specially for CI. It uses CI infrastructure, so you can run all test tests via a browser and results are displayed back as a web page (HTML). It's very simple to use.

I suggest you test your Controllers as well. Testing model is ok, but model is just the DB storage. Controllers contain all the "business logic" and are the place where most things go wrong.

Milan Babuškov