Skip to main content
When developing software, a certain level of quality is expected in order for the final product to be accepted. Unit testing is an important part of the process to ensure that the software lives up to that standard of quality. Unit testing focuses on taking the smallest testable parts of software and matching the actual results of that unit against the expected results for a given input.



With the 2019.1 release of the Software Factory we have taken steps to automate this process. Unit testing has always been possible, but up until now involved a manual process. Developers had to manually define the test, execute it and compare results. With unit testing in the Software Factory we’ve aimed to make this process efficient, reusable, and easy to implement in new and existing projects.



Logic concepts

As mentioned in the intro, a unit is the smallest testable part of the software. The logic concepts in the Software Factory are an ideal candidate for this. They consist of small pieces of functionality, require input data and produce a predictable result. The logic concepts we included in this release are:


  • Defaults
  • Layouts
  • Contexts
  • Badges

These logic concepts are the most ubiquitous throughout projects created with the Software Factory and provide a good jumping off point for introducing unit tests.



Getting started



We’ve created a new screen for Unit tests called… Unit tests! This screen can be found under the Quality menu group or as a tab in the functionality modeler.



The list on the left side shows all objects for which unit tests can be written. Clicking on an object will show the unit tests for that object or you can expand it to show the available logic concepts. To add a new unit test simply create one on the form for the unit tests. At this point we can already begin testing by running the Execute unit test task. By doing this, the procedure will be executed with a default set of values. This will not be a real functional test run just yet, but can serve as an indicator whether the stored procedure is available on the database and has properly compiled. To create an actual test case, input values need to be entered under the Input tab. Executing the unit test will then use these values for the input parameters of the stored procedure.



We can also measure if a unit test returns an expected output for a given set of input values. Assigning values for the output parameters under the Expected output tab will compare these values to the actual output. When a unit test has finished executing, the results will be displayed under the Results tab. This will indicate whether the test run was successful, what the actual output was and if any messages were returned.



When things go wrong

In a perfect world, our code would always execute successfully. But this is not a perfect world, and things can go wrong. And sometimes we want to simulate things going wrong, to see if we’ve handled an error correctly for example. By defining a message on the Expected message tab, which will be compared to the actual message received from the unit test execution, and checking the Should abort checkbox for the unit test, we can see if things went as expected, even if they didn’t go “right”.



Upgrading

After finishing a product upgrade, one of the main concerns is whether the upgrade broke anything unexpectedly. To this end we’ve added the ability to do a regression test for all unit tests. From the Creation screen select the Unit test tab. Here all unit tests will be listed. They can be executed separately or in a batch by selecting the desired unit tests and running the Execute unit test task.



The future

This first iteration of unit testing is already quite robust, but we’re working on adding even more features to it. Some things to look out for in the future:


  • Requirements and design integration.
  • Unit tests for Task, Triggers and Subroutine logic concepts.
  • Smoke tests.

We’re also working to add preparation code, which can be used to test some of the more complex logic code. We will also be looking at ways to automate the creation of mock data to help create a test environment. But more on this at a later date.



We look forward to seeing how you are going to integrate unit testing into your development process!
Be the first to reply!

Reply