# NUNIT: A Unit-Test-Framework for Natural

**URL:** <https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples\
**Created:** [December 30, 2009, 2:23am UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451 "2009-12-30T02:23:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan3](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/stefan3/32/245_2.png) [@Stefan3](https://techcommunity.softwareag.com/u/Stefan3)\
**Post date:** [December 30, 2009, 2:23am UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/1 "2009-12-30T02:23:41Z")

</div>

Hello fellow Natural developers 🙂

I developed a Unit-Test-Framework for Natural applications as part of my Master’s thesis and I wanted to share my results with you.

With NUNIT you can write automated tests for your Natural modules (subprograms or subroutines) that can be run by the framework like you may know it from JUnit, NUnit etc. Here is an example TestCase (btw, is there any way to highlight the Natural source code? I could provide my GeSHi definition):

```auto
DEFINE DATA
PARAMETER USING NUTESTP /* parameters for a single test
LOCAL USING NUCONST /* NUNIT constants (error code etc.)
LOCAL USING NUASSP /* parameters for the assertions
END-DEFINE
*
NUTESTP.FIXTURE := 'Example TestCase 1' /* this TestCase's fixture
*
INCLUDE NUTCTEMP /* the template method (SETUP -> TEST -> TEARDOWN)
INCLUDE NUTCSTUB /* stub implementations of SETUP and TEARDOWN
*
DEFINE SUBROUTINE TEST /* the main test routine
*
**************************************************************
IF NUTESTP.TEST EQ 'comparing two equal numbers should pass' /* name of first test
**************************************************************
  ASSERT-LINE := *LINE; PERFORM ASSERT-NUM-EQUALS NUASSP 2 2 
END-IF
*
**************************************************************
IF NUTESTP.TEST EQ 'comparing two different numbers should fail' /* name of second test
**************************************************************
  ASSERT-LINE := *LINE; PERFORM ASSERT-NUM-EQUALS NUASSP 1 2 
END-IF
*
END-SUBROUTINE
*
END
```

NUNIT parses the TC’s source code and checks whether it provides the needed inclusions, subroutines etc. shown in the listing. The actual tests are defined in the IF-branches (over ten different assertions are already available). The tests’ “names” are plain text so it is possible to provide meaningful descriptions about what is tested.

The attached screenshots show the results of a test run including a “red bar”.

 ![](https://global.discourse-cdn.com/techcommunity/original/2X/2/287a03e23c8655618ae39522f49464179e6015f4.jpeg)  
 ![](https://global.discourse-cdn.com/techcommunity/original/2X/e/e0c13d5318abff27062504d7c96c22d0370d2771.jpeg)

If you are interested in the framework or Unit-Testing in general, feel free to try out NUNIT and comment on it. You can download the source code and the part of my Master’s thesis about NUNIT (German) from my blog: [url][http://blog.stefan-macke.com/2009/12/29/nunit-a-unit-test-framework-for-natural/[/url]](http://blog.stefan-macke.com/2009/12/29/nunit-a-unit-test-framework-for-natural/%5B/url%5D)

What are your experiences with automated tests in Natural? Does anyone do automated testing? How do you do it? If not, how do you test your applications? Has anyone tried TDD?

---

<div class="post-metadata">

**Author:** ![Coder](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@Coder](https://techcommunity.softwareag.com/u/Coder)\
**Post date:** [January 13, 2010, 10:55pm UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/2 "2010-01-13T22:55:07Z")

</div>

Really nice work. Congratulations.

KlaBueBaer

---

<div class="post-metadata">

**Author:** ![Rudolf3](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Rudolf3](https://techcommunity.softwareag.com/u/Rudolf3)\
**Post date:** [January 14, 2010, 2:23pm UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/3 "2010-01-14T14:23:54Z")

</div>

Hi Stefan,

Great to hear that I’m not alone here. The last 10 years I have been developing with Java/C# and recently I started developing with Natural again. The first thing I missed were unit tests. I also created a test framework using Natural classes (Also inspired by JUnit. Yours looks better at the moment ;-). I will have a look and try to incorporate some of your ideas within my framework or vice versa.

The great thing with unit tests is that we, as Natural developers, can refactor our code without fear (I already enjoyed this privilege). TDD is the next step. The only downside is that it will take some time for the other developers to make this mind shift (they also created ‘unit’. but they throw it away. A Unit test is a proof that your ‘service module’ meets some quality standard. Why should you throw that away???).

What I also like to see (as a next step) is a way to perform CI (Continuous Integration). The customer I’m working for is thinking about using Agile development (SCRUM) and, as you might know, this requires a decent test harness. So if someone has worked on CI I would very much like to hear about it.

Kind regards,  
Rudolf

---

<div class="post-metadata">

**Author:** ![Rudolf3](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Rudolf3](https://techcommunity.softwareag.com/u/Rudolf3)\
**Post date:** [January 14, 2010, 4:43pm UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/4 "2010-01-14T16:43:42Z")

</div>

Hi Stefan,

That looks great. But don’t expect that it will work on other machines. There is some hard coded stuff there (path to the unit tests).

That’s why it’s maybe a good idea to turn these unit tests into classes (my colleague suggests to use user exists), so that these parameters can be set (what about DI. Anyone interested in building Natural SPRING).

Cheers,  
Rudolf

---

<div class="post-metadata">

**Author:** ![Rudolf3](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Rudolf3](https://techcommunity.softwareag.com/u/Rudolf3)\
**Post date:** [January 15, 2010, 3:08am UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/5 "2010-01-15T03:08:42Z")

</div>

Hi Stefan,

\*TRIM() doesn’t work on mainframe. Personally I would like to see the same functionality between all platforms.

One of the pieces that are missing on the mainframe are functions. It makes programming much more interesting. I don’t know why it is not supported, but it should be possible to turn a subprogram into a function since one of its parameters returns a result. The rest is just syntactic sugar.

Rudolf

---

<div class="post-metadata">

**Author:** ![Stefan3](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/stefan3/32/245_2.png) [@Stefan3](https://techcommunity.softwareag.com/u/Stefan3)\
**Post date:** [January 15, 2010, 5:14pm UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/6 "2010-01-15T17:14:56Z")

</div>

Hi Rudolf.

That was exactly my background, too. Developing C# for a while now and experimenting with Scrum there was simply a need for a Unit-Test-Framework in Natural. The original version was developed by a colleague of mine (see [this thread](http://tech.forums.softwareag.com/viewtopic.php?t=13968)) and I refactored it (God, I love to refactor code covered by tests ;-).

I also tried to use Natural classes for the framework but they have some drawbacks (e.g. nobody I know uses them ;-). My current approach marks the end of a long journey through the depths of Natural, especially when it comes to the issue of something like “interfaces” (which comes in very handy when writing a Unit-Test-Framework but isn’t supported by Natural). So I ended up writing my own parser for the test cases…

CI is an interesting feature, too. But what exactly do you have in mind when it comes to Natural sources? Something like automated tests running after each “commit”? We use Subversion for versioning control but the problem with that is, that the source code is already located on our Unix server and doesn’t have to be commited to a repository first (in fact, it is easy to forget a commit after you changed the sources).

What hard-coded part are you talking about exactly? I tried to move the OS-specific code into two modules (take a look at my component diagram in the upper right corner) that indeed need to be changed when porting the framework. Is there even more code that is platform-specific in other modules?

 ![](https://global.discourse-cdn.com/techcommunity/original/3X/0/6/062576ed3cb9567f35e5cd1b1027a468bdc71fb2.png)

Mh… I didn’t know that \*TRIM() doesn’t work ☹ But I don’t think that it’s that important because it should only affect the text output. Maybe you could just remove the calls!?

Anyways, thanks for the comments. If you have more issues I would like to hear about them. Maybe we could work together and fix them…

---

<div class="post-metadata">

**Author:** ![sorna\_sambavi](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@sorna\_sambavi](https://techcommunity.softwareag.com/u/sorna_sambavi)\
**Post date:** [June 22, 2011, 6:09pm UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/7 "2011-06-22T18:09:05Z")

</div>

Thanks for sharing. :roll:

[Scrum Process](http://learnsoftwareprocesses.com)

---

<div class="post-metadata">

**Author:** ![mwessjoh](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mwessjoh](https://techcommunity.softwareag.com/u/mwessjoh)\
**Post date:** [March 15, 2012, 11:38am UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/8 "2012-03-15T11:38:21Z")

</div>

Hi,

we published the NatUnit-Testframework on Sourceforge:

> **[NatUnit](https://sourceforge.net/projects/natunit/)**
>
> Download NatUnit for free. Unit-Test-Framework for Natural (SAG) NatUnit is a Unit-Test-Framework for Natural. Natural is a 4GL programming language from Software AG (SAG).

Feel free to download and using it.

We liked if you are helping use to improve the Unit-Framework.

Best regards,

Markus Wessjohann

---

<div class="post-metadata">

**Author:** ![Stefan3](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/stefan3/32/245_2.png) [@Stefan3](https://techcommunity.softwareag.com/u/Stefan3)\
**Post date:** [May 17, 2019, 10:47am UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/9 "2019-05-17T10:47:04Z")

</div>

NatUnit 2.0 was released this week! We completely renewed the framework and removed any dependencies on the file system or other frameworks of ours. It’s written in 100% Natural and should run on any platform now (LUW as well as Mainframes). Please check it out and leave us a comment.

[https://natunit.com/](https://natunit.com/)

By the way, it’s completely open-source. So you’re free to change the code or add features. We use GitHub for collaboration now.

> **[GitHub - AlteOldenburger/NatUnit: Unit Test Framework for Software AG's Natural](https://github.com/AlteOldenburger/NatUnit)**
>
> Unit Test Framework for Software AG's Natural. Contribute to AlteOldenburger/NatUnit development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:57pm UTC](https://techcommunity.softwareag.com/t/nunit-a-unit-test-framework-for-natural/92451/10 "2021-04-02T14:57:53Z")

</div>


