0

Say I have this code:

Design
{
    public function load()
    {
        $this->loadProduct();
        $this->loadService();
        ...
    }

    public function loadProduct()
    {
        try
        {
            $this->product = new Product();
            $this->product->spec = $this->product->loadSpecs($this->a, $this->b, $this->c);
        }
        catch (\BadFunctionCallException $e)
        {
            $this->error = true;
            $this->emsg = $e->getMessage();
        }
    }
}

Questions:

  1. Do I test loadProduct function only?
  2. Do I test Product class only?
  3. Do I move loadProduct's code into load (thereby removing loadProduct function from existence, and test the larger load function (as part of Design class)? Say I may want to do this as part of clean up/reorganization of legacy code.
  4. Something else?
2

You should test sufficiently to provide adequate code coverage. Sufficiently (and adequate) vary on the risk associated with an undetected problem in your code. The cost to fix a problem after development (assuming a classic SDLC) is significantly higher then the cost to fix during development, but the risk may be minimal. So, really that is another way of saying that it depends on your context. Another point to remember is that testing does not "prove" correctness, nor does it "prove" your software is bug-free - all testing can do is provide you with information. For more, I recommend the book "Perfect Software: And Other Illusions about Testing" by G. Weinberg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.