CrimpJiggler Posted February 1, 2014 Share Posted February 1, 2014 I read the chapter on testing in the guide, but I'm still having trouble understanding. To learn new things, I like to implement them into my project, so I setup a test case for a page I'm having trouble with, I used "cake bake" to setup all the fixtures it requires, and heres the test I added: public function testEdit($id = NULL) { $substanceList['slug'] = array('substances_category','compound','plant','ailment','product','preparation'); $substanceList['model'] = array_map(function ($value) { return Inflector::classify($value); },$substanceList['slug']); foreach($substanceList['model'] as $extraModel) { $rdata[$extraModel] = ClassRegistry::init($extraModel)->find('list',array('order' => 'name')); } $expected = 0; $result = count(array_intersect($rdata['Compound'],$rdata['Product'])); $this->assertEquals($expected, $result); } thats the method in my controller which is causing a glitch, the glitch is that when I try to load a list of items from the products table, it loads a list of compounds instead, so it loads compounds twice for some reason. I setup a test, which asserts that the list of compounds doesn't contain the same items as the products list. So I go to test.php and run the test for this controller and: so the problem that occured in the real situation, didn't occur in the test case. So I'm struggling to see what the purpose of testing is. Do I need to setup the code in test case, so that its pretty much identical to the actual controller? One other thing: I installed xdebug so I can "analyze code coverage" but when I click analyze code coverage, it just says " No files to generate coverage forwhat does that mean? Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted February 2, 2014 Share Posted February 2, 2014 According to your new slavemaster, you must test everything. So to answer your question, yes. In the real world of getting things done, maybe not. As the dev, I think you have to decide when a test is worth doing. Remember, there is more to testing than unit testing. All your functions can be perfect, but if they don't accomplish the end goal, your testing was worthless. Quote Link to comment Share on other sites More sharing options...
ignace Posted February 2, 2014 Share Posted February 2, 2014 (edited) So I'm struggling to see what the purpose of testing is. To verify it works as expected. It's also used to replicate bugs, the fix will make the test pass and thus fixes the bug. Of course this is assuming the programmer responsible wrote good tests. All you have verified is that the Compound model does not return Product models and it doesn't so your understanding of the problem is wrong. So, perhaps you should review your code and find what is really going on and then write a new test matching your new findings and make sure the test fails (meaning you replicated the bug in your test). Then make your changes to your code and the end-result should be that your test succeeds. Edited February 2, 2014 by ignace Quote Link to comment Share on other sites More sharing options...
CrimpJiggler Posted February 7, 2014 Author Share Posted February 7, 2014 What kinda tests should I be setting up? For example, I made a web spider Helper which downloads wiki pages and extracts info from it, what kinda tests should I set up for that? One problem with it is if it gets pointed to a wiki page that doesn't exist, or else one that doesn't have the kinda data its searching for, then it can't extract any data and things go wrong. Should I make a test that asserts that the variable containing the extracted data is not empty? I suppose this would be useful if I set up a series of mini tests like this, that way when something goes wrong it'll help me narrow down where the problem is. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.