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")
public function securityCheck()
{
}
private function checkDuplicateTXN()
{
}
private function checkTamperedEmail()
{
}
private function checkIncompletePayment()
{
}
private function checkWrongCurrency()
{
}
private function checkWrongPayTo()
{
}
private function processErrors()
{
}
The point of entry into this class is securityCheck(), where two sets of data will be compared with each other. The return results would be an array of flags, indicating which checks have failed, be it an incorrect invoice number, tampered email and etc.
I would like do test each of the function individually. Any advice on how should I do that, or do I need to define a different set of data for each case?
If those methods are private then you should not be testing them. However, it looks as though each method would have some value if it was made public? Would it hurt anything if you were able to perform each check by itself?
Corrrection, you SHOULD test them but you should not test them directly. Your tests should test the public methods which in turn call the private methods. If the private methods fail the tests should be crafted in such a way that the main tests fail too. Basically you just need to think of your ideal API, write it up, figure out what you expect a given function to return, and write tests for each different scenario
Sorry, I was midleading with my previous answer there. jshpro2 is right. Basically although you're sending all data through one public method, you still wants tests for the various scenarios like testUsingWrongCurrencyFailsCheck() and so on.
Yeah but at the same time you don't want one extreme or the other. You don't want only 1 unit test for your application and a ton of private helper methods, at the same time you don't want a "god method"