My personal testing method: Request for Comments

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
Bruno De Barros
Forum Commoner
Posts: 82
Joined: Mon May 12, 2008 8:41 am
Location: Ireland

My personal testing method: Request for Comments

Post by Bruno De Barros »

I tried learning Simpletest, but I'm afraid I'm too lazy to get to know a unit testing framework when I can simply build my own, the way I like :P.

So I went forward and made my own Unit Testing Class.

Currently, it has assert() and run() as functions.

You make a class then, that extends my Unit Testing class (somewhat like simpletest). Then, you have your methods there, that use assert($test, $expected, $name); to check if the expected result is the one I want. It runs on ===, so the expected result must be exactly the same as the expected result. Otherwise, expecting true and getting 'Oops. I'm a string' would be considered as a passed test. And that, I don't want.

The run() method simply looks for all the functions in the class and runs them. Whenever assert() is called, it adds up to the list of run tests, as well as working and non working tests. When a test fails, it also tells me the given result, and the expected result.
Then, it packs everything up and puts it in a nice looking (similar to Simpletest) template, with everything organized for me.

So, I'm wondering, what do you think of my (small) solution? It makes my testing a hell lot easier :P, and I always put several tests, with correct and incorrect values, and the expected results, so I can get a very clear view of what is working and what is not.

This has worked perfectly for me, as I was able to create several real life situations with fake data. Also, because I have a strict policy for my models (they receive their input from arguments and arguments only, no direct access to globals is permitted), my tester always works. If I had to created fake $_POST or fake $_GET, it would be much more annoying.

And I have a global test runner that runs ALL the tests, after I change stuff, and it sees if EVERYTHING is working perfectly. It's so much better than changing stuff, and then going to each page and testing out manually (which is actually harder, when you start dealing with stuff that is time consuming or just plain old boring, like filling out a form several times to test if filtering / validation solutions are working [Don't attempt that at home :P it's error prone and after a while you just stop bothering with it - it's like onion2k said]).

And as I make functions on the project, I make unit tests for them. And as the website grows, all the tests grow. So in the future, if I ever change anything, I'll just run a whole test and if anything goes red, I'll know that, and will fix it.

Chris Corbyn said that I would only understand it when I got the feeling of it. Now I know what he meant.

Come to think of it, :lol: I think I'm discovering the power of TDD accidentally xD.

Comments, anyone?

UPDATE: My reports are now somewhat different from Simpletest's. It shows a normal x/x test cases completed, x passed, x failed (I don't have exceptions, my tool is not that complex :P), and then it shows a breakdown of ALL the test cases. It gives you a list of what tests have been done and which ones have failed. For the test cases where all tests worked, they are hidden by default (you click on SHOW and a small javascript snippet shows them), whilst on failing test cases, they are displayed by default. This allows me for a simple view of the tests (the global report on top, and only the faulty test cases show what has been tested, and what tests have failed), and if I want to, I can go deeper, and take a look at what I am testing on each of the test cases.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: My personal testing method: Request for Comments

Post by Chris Corbyn »

One word. xUnit.

I'm just afraid that your "class" isn't going to offer the same architecture as any member of the xUnit family, which means you're not going to be able to apply tried and tested automation patterns and will therefore be more likely to end up with very difficult to maintain tests.

Learn an existing framework before deciding to write your own, or at least understand xUnit.
The run() method simply looks for all the functions in the class and runs them.
Ouch. No fixture setup methods can ever be added to your tests then?

Seriously, I appreciate that you've put a lot of work into building this class but you should really go back to the drawing board and learn what you set out to learn in the first place ;)
Bruno De Barros
Forum Commoner
Posts: 82
Joined: Mon May 12, 2008 8:41 am
Location: Ireland

Re: My personal testing method: Request for Comments

Post by Bruno De Barros »

Currently, I was using a very archaic mode of making the setups. It was basically just putting the setup and teardown process inside the tests.

You are right, I should learn a unit testing framework. And I am (Simpletest). This is just my way of getting excited about the matter. Because now I know better what test units are for (remember the topic I made the other day about their use?).
Bruno De Barros
Forum Commoner
Posts: 82
Joined: Mon May 12, 2008 8:41 am
Location: Ireland

Re: My personal testing method: Request for Comments

Post by Bruno De Barros »

UPDATE: Thank you so much, Chris, for telling me straightforward that I should learn a unit testing framework, instead of trying to do my own. I know how to work with SimpleTest now! It took me 10-15 minutes, but I converted all my tests to SimpleTest :| Makes me wonder how I let myself be so lazy as to ignore SimpleTest. :P
Post Reply