Jump to content

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


dennis-fedco

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.