0

I am currently creating a project using symfony2, i am using PHPUnit vendor to functional test my code. I am facing a problem that the functional test time increases as the projects gets bigger. Note: i am using Fixtures to be loaded for every functional test function.

My question here? what is the best practice to implement functional test that run in a reasonable time.

on another hand, Is there any bundle or tool that i can use to speedup this process?

Dahab
  • 518
  • 1
  • 5
  • 23
  • 2
    Unit tests should be isolated and not touch any external resources (that's what "unit" fraction in the term means). What you're doing is not "unit testing". – zerkms Apr 06 '15 at 20:57
  • @zerkms would you explain more! and what do you mean by external resources? – Dahab Apr 06 '15 at 21:05
  • 1
    Everything that requires any kind of fixtures or cleaning up or connecting remotely: database, filesystem, http, etc – zerkms Apr 06 '15 at 21:27
  • @zerkms so you mean i am doing a functional test not unit test? – Dahab Apr 06 '15 at 21:31
  • 1
    Divide tests up into those that require a full fixture load and those that don't. I don't find fixtures actually work that with for testing large applications. It's true that what you are doing is not unit testing, but for applications functional testing is arguably more useful. The old "unit tests needs to be isolated" mantra doesn't actually help solve the problem. Personally, I tend to test against a real world database snapshot but try not to make too many assumptions about it's current state. – Ryan Apr 07 '15 at 02:24
  • @Ryan: it's not "mantra", it's definition. You either follow the terminology or not. You can call it whatever you like, but it would be better for everyone if everyone used the same terminology base. – zerkms Apr 07 '15 at 08:22
  • @zerkma: I agree. It's best we use the right words and the definition of unit testing is clear. It's just that I've seen a lot of valid questions about how to do effective integration testing get stuck on terminology. I think part of the issue is that all the best practice testing examples are for frameworks and libraries, where unit testing makes sense. But most people learning to write tests, probably want to mostly write functional tests. – Ryan Apr 09 '15 at 01:15

2 Answers2

2

Your question is complex and it is very hard to say exactly problem of delay.

First of all you can divide your fixtures that possible to load before your test suit and other part that can be loaded via setUp method.

2nd advice that can really speedup you tests process is multi-threads run. I use "fastest" lib that allow me to speed up my tests in about 3-4 times (on i7) in compare with one thread run.

https://github.com/liuggio/fastest

find tests/ -name "*Test.php" | ./bin/fastest "bin/phpunit -c app {};" 
Evgeniy Kuzmin
  • 2,384
  • 1
  • 19
  • 24
1

Just some addition about arguments for unit/functional test. As I see the topic is about "functional" tests and if the tool is PhpUnit, it doesn't mean that tests must be "unit", because it is possible to make functional tests with it too, but I believe that it is not the best choice of the tool for functional tests.

I will recommend you take a look to other a great tool for functional tests like Behat (http://behat.org). It will allow you to not only work with functional tests more comfortable, but use BDD(Behavior Driven Development) approach for your development process

Just small example how we use it for functional testing of shopping cart http://www.youtube.com/watch?v=XIUmDGaaZWM

Evgeniy Kuzmin
  • 2,384
  • 1
  • 19
  • 24