I noticed that symfony automatically creates functional tests for all module actions, but i'm curious if it creates unit tests too. Maybe through a plugin or something.
The functional tests you mean are stubs - they do a very basic test, nothing else. There is no way to get unit or functional tests autogenerated for you - how would symfony know what's the expected behaviour of your appication?
Related
During an interview, project manager asked me the following question:
I see in your resume that you are using PHPUnit 4 for tests? Why don't
you use the built-in testing of Symfony?
I answered:
What I know is that Symfony app testing is done via PHPUnit, which is
recommended from the docs of 2.3 and 2.7. I don't know if Symfony3
comes with a testing component!
Was my answer correct? Thanks for the explanations.
Yes, you are correct. Symfony has a WebTestCase (extending the KernelTestCase where you can find that it extends PhpUnit) for functional testing. Additionally Symfony provides a PhpUnitBridge that provides helpful stuff for writing PHPUnit-Tests for a Symfony app, e.g. to make tests fail that use deprecated components. Both rely on PHPUnit and provide additional capabalities on top of "vanilla" phpunit.
There are alternative testing tools, such as phpspec for writing unit tests and Behat for higher level tests (functional and acceptance testing), but both are not used inside Symfony and therefore don't really seem to be what was being asked about.
Additional information to your answer:
In my experience, WebTestCase also bootstrap kernel as static method in all test. Due to that, is not so good to Unit testing by that tool, as this test should be fast. They design this with functional testing controllers and actions but to not need start HTTP server.
Then for:
unit testing, build-in in is not good option
functional testing, it was original intention, but i think, Behat is better solution
system testing - not so good.
Summary, that is why i don't use this tool.
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?
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 {};"
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
Is it possible to with two different testing methodologies? For example PHPUnit and PHPSpec in the one applicationor package?
Does anyone have any guidance?
It is possible to use PHPSpec and PHPUnit in the same application. Or you could use something like Codeception (http://codeception.com/) which does Unit Testing, Functional Testing and Acceptance Testing all in one package.
While my other Codeception tests are running (acceptance, api, etc,), very little of the unit tests will run. It does not see any tests of type Test.php, only Cept.php and Cest.php. It does not accept (errors) any assertion tests such as "$this->assertEquals($expeced. 'expect this'). How do I trouble shoot this as the tests that fail only return:
Codeception PHP Testing Framework v1.8.1
Powered by PHPUnit 3.7.28 by Sebastian Bergmann.
phpunit seems to be installed as I see it in the vendor directory. I can run it directly from the command line to see its help. But that is about it. Are unit tests generally flaky with the Laravel/Codeception combo? Is there some config I am missing???
Seems like the problem was the creation of the test class.
You declared you want to use \CodeGuy; - you don't want to do that.
Instead you want to extend your class like this.
class SampleCest extends \Codeception\TestCase\Test
My advise: use codeception to generate your unit tests.
codecept.phar generate:phpunit unit Sample
I've got an application developed in kohana 3.2. I want to write some functional tests that will affect database content. I would like to load the database from a dump file each time I run all functional test suite (so that I'm sure I can write and remove from the database as much as I want).
How can I do that in Kohana? Does it support functional testing anyhow?
Kohana supports unit testing with the unit test module and php unit installed. It sounds like you may be possibly want to do unit testing with mock objects. You could also set up your database using your models or a dump file too. Full functional testing is possible as well. A good place to start is enable the testing module and then start here...
https://github.com/kohana/unittest/tree/3.2/master/guide
And phpunit here...
https://github.com/sebastianbergmann/phpunit/
I use Codeception for all of my acceptance test, functional tests, and unit tests which is powered by PHPUnit. It is the best testing framework that I have found for PHP. You can pre-load sql dumps prior to functional tests and query directly against the database. It also integrates easily with Selenium for testing browsers.
I released a vagrant development environment with an empty checkout of Kohana 3.3.1 if you want to try it out Codeception. The tests are incredibly easy to write.
Intro to Vagrant with Kohana and Zen Kommerce
Codeception