Reputation: 1912
I have a big application which i want to test with phpunit. In the first step i want to test if every page is accessible and returns a response code 200.
This is how i do it:
public function testIndexActionCanBeAccessed()
{
$this->dispatch('/');
$this->assertResponseStatusCode(200);
}
But as i said before, my application is a big one. So there are many pages to test. These tests will take a long time.
Is there a way to speedup those tests or aren´t these tests relevant?
THANKS FOR HELP
Upvotes: 1
Views: 2583
Reputation: 70933
I once had the situation that a rarely used page was broken due to a code change, and the management was loudly complaining. The failure would have been easily spotted by simply requesting that page with wget
- and that's what I added as a regular job to our Jenkins then. That job never failed afterwards, happily requesting two or three pages day after day, month after month, for about two years (then the pages were removed).
If you are in a situation where there is no better testing available or would be too cumbersome to implement, testing for HTTP status codes would be a valid approach. But as you saw yourself, this will get way too slow very fast, because you must always test the whole system as one big black box. And you need everything working in a test environment.
If you have a nearly untestable system right now, using functional tests that remotely control the application with things like Selenium are a good first step to detect failure quickly. You probably want to execute these test in parallel, which would require proper hardware power, most likely in the form of multiple machines just to execute the Selenium clients.
On the other hand, you should aim for getting more unit tests. These will run really fast, because you will inject mock objects as a replacement for real things like the database connection. Without a database in the background, the test will not communicate with the network, not write and read from disk - the mock object is in memory and give the needed answers almost instantly.
In combination, the unit tests together with a selected set of functional tests (and probably some integration tests that put some bigger parts together and test them individually, but not the whole application) will show that everything works as expected.
But with functional tests alone, this will never be the case.
Upvotes: 2
Reputation: 5726
From your point of view, why such a test should be relevant ? You are running the test suite in test environment or on your dev machine, so the application will implicitly be "online". If you really need to test if the application responds, perform a single test for this, not one for each page.
Upvotes: -1