ArcherPoint Dynamics NAV / Business Central Developer Digest - vol 268
The NAV community, including the ArcherPoint technical staff, is made up of developers, project managers, and consultants who are constantly communicating, with the common goal of sharing helpful information with one another to help customers be more successful.
As they run into issues and questions, find the answers, and make new discoveries, they post them on blogs, forums, social media...so everyone can benefit. We in Marketing watch these interactions and never cease to be amazed by the creativity, dedication, and brainpower we’re so fortunate to have in this community—so we thought, wouldn’t it be great to share this great information with everyone who might not have the time to check out the multitude of resources out there? So, the ArcherPoint Microsoft Dynamics NAV Developer Digest was born. Each week, we present a collection of thoughts and findings from NAV experts and devotees around the world. We hope these insights will benefit you, too.
How to Test Your Code Without Data
Bill W. asks: “How do you test your code without data? They have all sorts of handy libraries with functions specifically designed to help generate data to match your needs.”
Figure 1 – Dynamics NAV Function Library
Tom H. wants to know: “How can we find these libraries? Which versions of BC/NAV are they in?”
Matt T. replies: “They are in every version back to 2009. For C/AL, you'll find them in the installation media in the TestToolkit folder. For AL, just run the Import-TestToolkitToNavContainer powershell command. You'll find them in the 130,000-object range.”
Unit Tests in BC 15 Now Too Good Not to Use
Bill W. shares: “Unit tests in BC 15 are finally in the realm of usable, actually working well enough that you should use them:
- The tests are readily available in the Docker containers
- The toolkit loads pretty quickly
- Workspaces in VS Code finally works with compiling both the app and test in the same project.
Loading all tests takes a while, approximately 3 minutes, but the toolkit-only components take approximately 30-50 seconds versus nearly 10 minutes in BC14. All tests in BC14 take nearly a half hour to load.
My unit test code is still really bad, it's a real change to start with a test first (acceptance-test driven development—this is what MS and many Partners, etc. are now doing GIVEN/WHEN/THEN), and it added a bunch of time to the development effort, which was mostly trying to figure out how to write tests.
However, without doing the test, I would have never caught a bug in the logic of this small app we're submitting to AppSource. We added a new feature that altered some of the logic that rolled up quantities that had previously been manually tested. Going backwards, I decided I should probably create some more tests to cover the new scenarios, and one of them was failing. Was it my test or my logic? The original logic was busted. Now that I had a test case, I was able to run my test cases extremely quickly (create a work order, create a line on the work order, post job journal lines, check lines now attached to original work order, and confirm the quantities) over and over again until I was able to get a successful result.
We're also able to attach results to the AL builds now, creating the nifty looking output with the circle graphs, like shown in Figure 2.”
Figure 2 – Unit Test Output Graph in MSD365 BC15
Figure 3 – Unit Test Output Graph in MSD365 BC15 Results
Bill W. provides an update later: “Having tests paid off again. I needed to add a permission file to the application and test with multiple user accounts, and permissions. Going though each scenario took seconds versus manually having to verify. BC 15 adds about 3 minutes to a build; BC 14 add about 11 minutes to a build.”
If you are interested in Dynamics NAV and Business Central development, be sure to see our collection of NAV/BC Development Blogs.
Read the "How To" blogs from ArcherPoint for practical advice on using Microsoft Dynamics NAV and Dynamics 365 Business Central.