Write modern Unit Test with 4D? Yes it is possible !

A lot of 4D developers ask if we can write unit tests within 4D. Yes you can write unit test with 4D but there was no easy way to do it. You must create your own routine.

One component was existing long time ago, you can still find the source code for v12 here markschaake/UnitTester4D

If you look at the code, you will maybe, like me, be repeal by the complexity of the architecture. Well, it was done long time ago and without the object notation so I will not blame.

I read since long time ago the posts about the JavaScript developer Eric Elliot which encourage people to use TDD (Test Driven Development) architecture. With JavaScript, you have dozen of libraries to write unit tests. You can even write tests for the graphical part as everything is readable in the DOM.

In 4D it is a little bit more complexe. You can write unit tests, and partial integration tests. But everything that touch the GUI is really complicated to do (not to say impossible). The only ones that I ever been able to see doing some GUI tests are the 4D Services with some specialists (you can find their service here : Quality Assurance Automation Services).

So, inspired by the RITEway test library written by Eric Elliot, I wanted to do something similar and as simple as it.

What Eric Elliot say's, is that some tests library fails to describe correctly a test. Here is what a test should have :

  1. What is the unit under test (module, function, class, whatever)?

  2. What should it do? (Prose description)

  3. What was the actual output?

  4. What was the expected output?

  5. How do you reproduce the failure?

The description of a test is simple, here is a screen shot of a test with 2 assertions.

The component also have a main window to display the results :

Here one test fails

I also want to share it freely to the 4D Community. You can find it in my company Github repository : AJARProject/AJ_Tools_UnitTest

You will also find the documentation.

Hope this component will be appreciated and help to write proper tests. If you have any questions, don't hesitate to ask me.

Also be sure to read those 2 article that inspired me to write this component. They also explain very well what are the different kind of tests :

JavaScript Testing: Unit vs Functional vs Integration Tests

Rethinking Unit Test Assertions

112 vues0 commentaire

Posts récents

Voir tout

List of 4D Components and Plugins

I realize that there is no list of existing components and plugins in 4D. I think it can be cool to make such kind of list to try to have a kind of catalog where people can look at to see what is avai