Unit testing with Software AG’s Natural – is that even possible? Let’s find out in the very first episode of the Legacy Coder Podcast.
Podcast: Play in new window | Download
Unit testing Natural applications
- Why would I want to unit test my Natural code?
- You get instant feedback whether your code works. That’s fun! 😀
- You get a safety net for refactoring and optimizing your Natural code.
- You can catch regression as early as possible. That makes evolving your code base easy and painless.
- Unit tests can be integrated into your build process (Continuous Integration, Continuous Delivery, Continuous Deployment).
- Unit tests are the first step on your way to a fully automated build process.
- What tools are available for unit tests with Natural?
- Subprogram testing within NaturalONE
- Only subprograms can be tested.
- Different “language” for defining your tests.
- Tests have to be defined manually from a GUI.
- Tests cannot be executed from within Natural itself.
- Proprietary software maintained by Software AG.
- Professional support by Software AG is available.
- NatUnit – an open source framework for unit testing with Natural
- Everything that can be called from a subprogram can be tested (subprogram, subroutine, function).
- Tests are written in the same language that is used for production code.
- Tests can be written as Natural code with full IDE support.
- Tests can be executed within any Natural runtime.
- Open source project that can be extended by everybody – including yourself.
- There’s no professional support for the framework.
- Subprogram testing within NaturalONE
- What do I have to do differently when writing testable Natural modules?
- You need more fine grained modularization!
- You have to decouple the User Interface, Database access, and the core Business Logic from each other.
- You need to extract the functionality to test into its own callable module.
NatUnit in action
Here are a few screenshot of our NatUnit Eclipse plugin in action.
You can run a NatUnit test from within the IDE.
If the tests are successful, you instantly see the famous “green bar”.
And if the tests are broken, you’ll definitely notice that, too. 😉
Recommended reading
- I mention this book in the podcast episode: Test Driven Development: By Example* by Kent Beck. It was one of the first books on the topic of TDD and is a short read and still relevant after all these years.
* - The part of my Master’s thesis about the development of NUNIT. I give a step by step introduction of the test driven development of NatUnit itself including code samples.
- Here’s a blog post I wrote about NatUnit a few years ago: NUNIT: A Unit-Test-Framework for Natural. It also includes a UML diagram of the framework’s initial architecture.
Is there any way to do performance or stress test in Natural? For example like Apache JMeter, you can define how many Users, threads and repetitions to call a task?
Hi Amjad, not that I know. However, you could script calls to NatUnit and simulate multiple users. Just start a fews Natural sessions from a script for example.
Hi Stefan,
here are a few remarks to NatUnit:
The NatUnit only works on OpenSystem, but there is a german company which migratet it to the mainframe.
You can also test programs and copycodes. Only make sure that you come back to the TestCase after call the program with FETCH RETURN.
Best Regards,
Markus Wessjohann
One point missed:
If you are starting with NatUnit, forget everthing you learn in the Natural workclass.
Hi Markus,
thanks for the additional information. You’re absolutely right: everything that can be “called” (or included in the case of a CopyCode) in Natural can be tested with NatUnit. However, I personally haven’t used NatUnit to test a program before, so I forgot to mention that! 🙂
Best regards,
Stefan