Live could be somewhat simpler – C&P chapter 5

Every time again I am creating a new function in C/SIDE, based on an existing one, I am overjoyed by the fact that it can simply be copied and pasted. Unsurprisingly it was the topic of one of my first blog posts: Live is simple if you know how – C&P chapter 2. But last week my joy was somewhat challenged.

Ever worked with the testability features available since NAV 2009 SP1? Or did follow my series on Test-Driven Development in NAV? (Ouch, don’t nag me on that one: I just couldn’t find time to finish it even though I am still eager to get to GREEN. [8o|])

The other day I was in a workshop with my German colleague Martin Staib to investigate the possibilities of an automated test suite for a certain feature taken the Application Test Toolset for Microsoft Dynamics NAV 2009 SP1 as our guide. So we initially created our own test codeunits as copies of MS codeunits. Molding and polishing them to our needs. Copying and pasting code and at a certain point in time also whole functions.

Now typically a test codeunit will hold a number of tests being a number of test functions, i.e. C/AL functions having FunctionType is set to Test. But for a number of reasons we will also need various helper functions. Normal functions (FunctionType set to Normal) that will be called from the test functions. As example have a look at the CreateSalesOrder function in the Sales Order test codeunit (134378) in the Application Test Toolset.

Working on our test codeunit we had created a couple of test functions and associated helper functions and after each change to our test code, as a good and very useful practice, we reran our tests exercising the TDD RED/GREEN/REFACTOR mantra. GREEN was great, RED always logical.

However, up to now we hadn’t been copying our own helper functions in the way I started this blog post with. So we did and adjusted the function to our needs and pressed F11 to get the codeunit compiled. Guess what? Hadn’t seen this one before:

Marked as TestMethod? Didn’t we copy and paste a helper function. A Normal function? Yes, we did, but apparently the platform will always set FunctionType to Test of any newly created function. Either by defining it from scratch in the C/AL Globals window or when dcreating one by means of C&P.

Typically this is a bug which most probably will not be fixed for NAV 2009. Indeed “live could be somewhat simpler”. But I know it will be as this issue should have fixed been for NAV 2013.

Leave a Reply

Your email address will not be published. Required fields are marked *