Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I test in phpunit? [closed]

I don't know if this is a too localized question, but I don't know what I should be unit testing with PHPUnit. Like for example on a simple user registration/login system, what should I be testing?

I hope you understand what I meant and enlighten me.

like image 711
Jürgen Paul Avatar asked Sep 04 '12 13:09

Jürgen Paul


1 Answers

PHPUnit is a unit testing suite, hence the name. Unit testing is, by definition, writing tests for each unit -- that is, each class, each method -- as separately as possible from every other part of the system. Each thing users could use, you want to try to test that it -- and only it, apart from everything else -- functions as specified.

Basically, you want to test each public (and possibly protected) method that can possibly fail. If your inner hacker is wondering "hmm...if i called this function like this, would it break?", then write a test that asserts that it doesn't. Just be careful that you're isolating the component you're testing; otherwise, you just have a bunch of tests that fail but don't give you a clue as to where the real problem is.

like image 176
cHao Avatar answered Oct 11 '22 12:10

cHao