Unit Tests for Data Transforms
Would you like to be sure your data transforms work as expected with a single command? And what about writing unit tests for your data transforms in a quick and simple way?
When talking about interoperability, there are usually a lot of data transforms involved. Those data transforms are used to convert data between different systems or applications in your code, so they are running a very important job.
Having a look at the concept of Test Pyramid and some articles about it, we can have a quick idea that having a solid base of low level cheaper automated tests is a better idea that testing only using the UI.
In an interoperability context, I've found in several projects that is really worth investing a little effort in writing data transforms unit tests, especially when we are working with different scenarios (e.g. HL7, custom messages, etc.). This will allow us to be sure our data transform logic is running as expected after introducing new changes. Even after resolving an issue with a data transform, we can easily create a new test with the message that caused the issue, so we are sure we are not getting the same error in the future.
A little helper that uses %UnitTest framework
To help you writing and running data transforms tests I'm sharing an example that uses IRIS %UnitTest framework. The goal is allowing you to define as external text files different sets of input messages and expected corresponding output messages for each data transform you want to test.
Let's suppose you want to create some unit tests for a data transform called Sample.Health.a31ToPatient, you should:
1. Create a new class that extends DataTransformTestCase. Set the <TestDirectory> parameter to the directory you are going to store your data transform tests.
2. In your <TestDirectory>, create a sub-directory called Sample.Health.a31ToPatient. This sub-directory will store the sets of input and expected output you want to test in the data transform.
3. In the Sample.Health.a31ToPatient sub-directory add input messages and expected output as *.in.txt and *.out.txt.
4. Run your tests! You can see the results in the %UnitTest Framework portal in IRIS. In case you are getting an error a *.gen.txt file will be generated, so you can compare the actual output Vs. the expected output and see what's wrong.
Run the example yourself
You can download, execute the example and read more details in Open Exchange.