Jump to content

phpunit: how to structure my test functions that test same SUT with different parameters every time?


Recommended Posts

I want to write a test for a complex legacy code function called load(); 

It loads various products from different product lines, so it can have many different actual parameters and number of parameters being used by it.  It has an if/then/else/if else/if else/etc. inside of it, and depending on the product, it uses almost completely different product logic.

 

I can call testLoad() inside of my PHPUnit test, but which product do I test?

 

well, maybe I can do testLoadProduct1(), testLoadProduct2(), testLoadProduct3(), etc.  Is that the recommended way to do it, or is there better way?

 

In a sense I need to call the same method with vastly different parameters, and the test object will be producing vastly different results every time.

 

I figure that with the way I proposed, if anything breaks, it will be immediately clear which methods (products) actually failed the tests, which should give me a clear idea what needs to be fixed or changed.  So maybe my approach is the best.  Still, just starting out with phpunit, I wanted to ask here to double-check.

 

Thanks!

Edited by dennis-fedco
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.