Using Of Fixtures/unit Testing

Hi guys.

Just wanted to ask, does somebody used Yii built in unit testing option in real projects.

As for me, I never had used this option in my projects. But maybe I another kind of developer that not use unit testing.

Add "rarely" and you can opt me in…

It might not be the wisest thing to do, but i have to admit writing good tests is often cumbersome and feels like doubling the effort required for a project. And if you decide to refactor, you have to refactor twice as much code. In the projects where i used tests i found, that i only had tests for the most obvious features. And writing tests for the rare tricky cases mostly wasn’t easy.

Maybe i should have another look at the yii testing framework. From what i’ve read it should be much easier now to e.g. set up fixtures. Something i always found most tedious.

Hi there,

I have to say that I don’t usually use (rarely as Mike said) testing in my projects. What I do is to code and check every block - variable (php-js) expected results, requests - responses speeds, but through firePHP, firebug and some time checking procedures (YSlow, etc…).

Once I am happy with it, I analyse again the code and try to find the best approach to use the fastest and cleanests algorithms.

After all that work, I don’t feel like doing more tests to tell you the truth. I suppose I should, but that will be when the projects I am involved require a more specific ‘care’ on performance and results. Once that come I will get back on the subject.

For me, this is a question of context & client requirements.

Working in the environment I do, the clients don’t pay for testing; they pay for a website at the end of the day. So, I re-use code I know that works, which gives me confidence in the final implementation, so the testing has been done by previous implementations. So most of the websites I do may take a week (client dead-lines), and it’d prolong that process beyond that, hence unhappy clients. But, in those cases, the websites are so small, testing isn’t that difficult to perform manually.

But I’m about to start developing a web-application (using Yii) that will be used as the core application a business to do their day-to-day work, and I want to offer a solid, tested solution. So in this case, where I have the luxury of time, and the need for it to be a solid application, I’ll be using the Test Driven Development model for creating the application (as described in the Agile Web Application Development with Yii 1.1 and PHP5 book).

I’ll get the reassurance that when it comes to adding new features and making bug fixes, I’ll have the confidence in running the tests to know that we have locally in our development environment works and I can add new features without worrying. I’ll also get the confidence to say to the client that the application works functionally based on the specifications we agree; no more, no less.

I look forward to working with the process, and while the initial learning curve will be painful (i.e. slow), it’ll create a better application in the end.

I use unit tests in every project. I rarely achieve 100% code coverage, but any nasty parts that look like they may be trouble, I always get tests in place around these.

Tests help me to re-factor and tweak client requirements more quickly and with more confidence.

Most importantly, they help me sleep well at night :wink:


Totally agree with this.

I’m not really following the true TDD method, but I always write unit tests for models’ methods. Because I’m using FAT model design, most of the logic is covered with tests.

Haven’t used functional tests yet, needs to check that out too.

Rarely do. Same reason with Mike. After knowing Yii, I just realize there is something called TDD to reduce buggy code. Since I am quite a sloppy programmer, I think I can use this TDD method to reduce the bugs. But what happened is, after coding the unit test, I’ve just realised there are a lot of bugs too in my test code and I just can’t help but using more time to fix the unit test to make sure it doesn’t buggy geez~ :(

Guess, I need to fix myself first before using TDD, or else it will take more time for me to write unit test.

I’m trying to follow TDD with my latest project, and all I can say It’s good. When It comes to model’s logic I always write the tests first. They give me confidence while coding.

Tho some days earlier I made bad test code, so It was buggy too :confused: As you say …

But the more I do it, the better I become, I hope. :)

I m not doing TDD strictly, but I like working with fixtures and a test database, and I love this green bar in netbeans (Alt+F6). If you have some workflows, status changes, calculations etc, unit tests are a time saver at the end.

I vote Rarely, because I only used unit and functionnal tests when I was contritubing to Prado.

But, I’m beginning a new project (very big project, complete rewrite of a huge VB.NET client/server application into a full web one), and I think I’ll developp it with unit testing in mind…

So, I could vote "just starting" too.

I guess a code generator to setup tests and fixtures would be helpful… However, it needed to take into account, that tests and fixtures would be re-generated again and again. And it needed a mechanism to keep the test code we implemented between those re-generate cycles…

I worked on four different Yii project, and on three projects we used unit tests. On my current zurmo project we have almost 1500 tests and almost 20000 asserts.

Check Zurmo Continuous Integration details.

Unit testing helps us much when we change some existing code, and make us confident that everything is working correctly after code changes. And unit tests can be used as additional documentation and examples how to use some classes/functions.

Nearly always. I wouldn’t dream of going back to the old, pre-TDD way, unless it was for an insanely simple project. Unit testing has cut my post-launch debugging time down by 95%, and it’s also really improved the way I design my code.