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 conceptsAs 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:
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 wrongIn 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”.
UpgradingAfter 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 futureThis 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 look forward to seeing how you are going to integrate unit testing into your development process!