C/SIDE Test-driven development

NAV 2015 includes the enhanced C/AL Testability feature set designed to support C/AL test-driven development. Test-driven development is an approach where the application tests are defined prior to the development of the application code. In an ideal situation, the code supporting application tests is written prior to, or at least at the same time as, the code implementing the target application function written.

Advantages of test-driven development include:

  • Design testing processes in conjunction with functional design
  • Find bugs early
  • Prevent bugs reaching production
  • Enable regression testing, preventing changes introducing bugs into previously validated routines

The C/AL Testability feature provides test specific types of Codeunits—Test Codeunits and Test Running Codeunits. Test Codeunits contain Test methods, UI handlers, and the C/AL code to support Test methods including the AssertError function. Test Runner Codeunits are used to invoke Test Codeunits, for test execution management, automation, and integration. Test Runner Codeunits have two special triggers, each of which run in separate transactions, so that the test execution state and results can be tracked. The TestRunner trigger descriptions follow:

  • OnBeforeTestRun is called before each test. It allows defining, via a Boolean, to determine whether or not the test should be executed.
  • OnAfterTestRun is called when each test completes and the test results are available. This allows the test results to be logged, or otherwise processed via the C/AL code.

Among the ultimate goals of the C/AL Testability feature are:

  • The ability to run suites of application tests both in automated mode and in regression tests:
    • Automated means that a defined series of tests could be run and the results recorded, all without user intervention
    • Regression testing means that the test can be run repeatedly as part of a new testing pass to make sure that features previously tested are still in working order
  • The ability to design tests in an "atomic" way, matching the granularity of the application code. In this way, the test functions can be focused and simplified. This allows for relatively easy construction of a suite of tests and, in some cases, reuse of test codeunits (or at least reuse of the structure of previously created Test Codeunits).
  • The ability to develop and run the Test and Test Runner Codeunits within the familiar C/SIDE environment. The code for developing these testing codeunits is C/AL.

The TestIsolation property of TestRunner Codeunits allow tests to be run, then all database changes are rolled back so that no changes are Committed. After a test series in this mode, the database after the test is the same as it was before the test.

Once the testing Codeunits have been developed, the actual testing process should be simple and fast in order to run and evaluate the results.

Both positive and negative testing are supported. Positive testing looks for a specific result, a correct answer. Negative testing checks that errors are presented when expected, especially when data or parameters are out of range. The testing structure is designed to support the logging of the test results, both failures and success, to tables for review, reporting, and analysis.

A function property defines functions within Test Codeunits to be either Test, TestHandler, or Normal. Another function property, TestMethodType, allows the definition of a variety of Test Function types to be defined. The TestMethodType property options include the following which are designed to handle User Interface events without the need for a user to intervene:

  • MessageHandler: Handles the MESSAGE statement
  • ConfirmHandler: Handles the CONFIRM dialogs
  • StrMenuHandler: Handles the STRMENU menu dialogs
  • PageHandler: Handles Pages that are not run modally
  • ModalPageHandler: Handles Pages that are run modally
  • ReportHandler: Handles Reports
  • RequestPagetHandler: Handles the Request Page of a specific Report

C/SIDE Test Driven Development approach should proceed along the following lines:

  • Define an application function specification
  • Define the application technical specification
  • Define the testing technical specification including both Positive and Negative tests
  • Develop Test and Test Running codeunits (frequently only one or a few Test Running codeunits will be required)
  • Develop Application objects
  • As soon as feasible, begin running Application object tests by means of the Test Running codeunits, and logging test results for historical and analytical purposes
  • Continue the development—testing cycle, and updating the tests and the application as appropriate throughout the process
  • At the end of the successful completion of development and testing, retain all the Test and TestRunning codeunits for use in regression testing the next time the application must be modified or upgraded

On PartnerSource, there is a full set of 7,000 to 9,000 regression tests available that were written by Microsoft for NAV 2013 using the NAV Testability tools. These are the tests that the NAV product developers used to validate their work. The number of tests that applies to a specific situation depends on the local version and specific features involved. At the time of writing this, the tools for NAV 2015 have not been released by Microsoft. To access the download for the NAV 2013 tools, search on testability and download Application Test Toolset for Microsoft Dynamics NAV 2013. Make sure your license is updated too.

Tip

Even if we can't use the older version of the tests for full regression testing, we can use them as models for creating regression tests for our own customizations.

Included in the supplement are the regression tests and various tools for managing and executing tests built on top of the testability features released for Microsoft Dynamics NAV. Also included is a coverage tool and guidance documentation for creating our own tests and integrating those with the Microsoft provided tests. This allows us to do full regression testing for large modifications and ISV solutions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.17.64