Ask HN: Unit test makes my mind blow up
4 comments
Right.
It looks like this only tests whether MocDB.DbGetOne() returns true, which it always does, and which is not testing the program, but the test.
You have to test the tests, to be sure they'll correctly test the program. Of course, then you also need to test the tests that tests the tests, and so on...
It looks like this only tests whether MocDB.DbGetOne() returns true, which it always does, and which is not testing the program, but the test.
You have to test the tests, to be sure they'll correctly test the program. Of course, then you also need to test the tests that tests the tests, and so on...
Code doesn't show properly on HN. Here's the http://pastebin.com/y1fhT33G
I think this question may be better suited for http://stackoverflow.com
code with mock usermapp
http://pastebin.com/w1HHtwKT
So my main question, is it really worth writing a unit test for a method like this? Or, is a unit test pretty much useless for a method like? Should time be spent on integration/end to end test? Someone please explain and expand on this.
Thank you
fyi: I know you can throw in a mock $user_map array in there to test for various user id and account id combinations. Is this really the way to go and write?
class User{ var $db;
function __construct(){ $this->db = new Some_DB(); }
/ * returns true if user user owns account */ function is_user_account($user_id, $acct_id){ $db = $this->db;
}
function test_is_user_account(){ $user = new User(); $user->db = new MockDB();
}
class MockDB{
function DbGetOne($sql, $params){ return 1; } }