Unit testing: How to get started?
Unit testing: How to get started? by Mitchel Mol - Blue Green Solutions

Unit testing: How to get started?

Starting with unit testing has proven to be one of the most difficult challenges for Mendix developers. Many reasons are given, such as needing to know where to start, it costs extra time, and not knowing what should be unit tested. And just as with many other challenges, Mendix explains the basics. They provide a module to get started, a basic explanation documentation, a learning path to learn some basics and a small guide. This is enough to get you interested. Unfortunately, the module has not been updated for years, except for maintenance and the required major Mendix upgrades. This is not as bad as it sounds, as the module stays relevant and contains the basics to get started. You can run a unit test directly from a user interface and get relevant output. But bear in mind, it is extremely basic, requiring much more work or some custom code to make it usable at scale.?

If you are serious about unit testing, there are two options. You could take a shortcut and use a commercial solution that offers many options. Or, if you follow this blog series, visit our January meetup, and when you need some in-person help setting this up, reach out to me for coaching or training.

Now let us get on with it and dive right into the specifics of getting started with unit testing!

I will first remove the doubts.?

I hear Mendix developers say it costs extra time, and they are partially right. However, unless these same Mendix developers never test their code, they make one common mistake.

They test their applications purely through the user interface and most likely run the same test multiple times. Then, they must explain the functionality to their colleagues during a knowledge transfer. And when they change something related or that very functionality, they must test it again. This is a lot of manual work, which also means human mistakes every time they “execute” the tests. This costs time, but we accept it as part of the process. At least a part of the time spent on manual testing should be diverted into regression unit tests. You build the unit test (preferably at the start) so you may run it repeatedly. It will even give extra context to your functionality.?

This approach will save you time, remove the human error that makes every manual execution slightly different, and allow for an easy knowledge transfer. After all, anyone testing it after you have implemented the code will just have to execute the unit tests.

Do you need to know where to start? Then I have already given you the solution. Follow the links from the previous chapters and read the rest of this blog series. At the end of it all, you should know exactly where to start.

What could you unit test? You should start with the basics.?

  • Validation microflows are excellent starts. They usually need more scope, already separated from the process of saving some data. This limits the unit tests to specific scenarios: a happy path, a failure path and an erroneous data scenario (causing system errors).?
  • Once you have mastered unit testing, you should move to your core business logic. Especially those calculations that require lots of manual input but have many logic bits in sub-microflows that need lots of steps to test manually. Build unit tests for each of those sub-microflows.?
  • The last low-hanging fruit item is elements of published and consumed API implementations. Import and export mappings, microflows taking care of published API functions, and handling of data imported during the consumption of API functionality from third parties.?

Validation microflow ready to be unit tested!
Unit test, testing the validation microflow

What is next?

There is much more to learn about unit testing, why it is essential and what could be possible with some much-needed changes to the module and the Mendix platform to make unit testing a core part of development on the Mendix platform.?

Next up, improvements to the module! Subscribe to the LinkedIn Newsletter and be the first to get notifications when it will be released!


Join our January 2024 meetup with more information about Unit testing and a look at what the low-code trends of 2024 and beyond will be!


#mendixignite #mendix #unittesting #meetup




Kokila B.

Mendix Lead at Equinix

1 年

A great article Mitchel. These are my exact thoughts and doubts with Unit testing. Would love to read more on this topic with some real implementations.

David Bawden

Manager at PwC UK

1 年

This is great news!

Liam Hanninen

Senior Mendix Developer and Architect

1 年

Unit tests seem much more approachable now. Thanks Mitchel Mol

Markus Travaille

Go test Mendix! Co founder en Chief Vision Officer bij Menditect

1 年

Thank you Mitchel Mol. Great contribution and I am looking forward to read the next chapters!

要查看或添加评论,请登录

Mitchel Mol ????的更多文章

  • Blue Green Mendix Speeddating - Google maps on Steroids recording

    Blue Green Mendix Speeddating - Google maps on Steroids recording

    It took some work to ensure the video was okay enough (we had three recordings from presenting this 3 times). For…

  • Google Maps on Steroids - Part 1

    Google Maps on Steroids - Part 1

    Mapping functionality is something I have been implementing since I started developing web applications 18 years ago…

    5 条评论
  • Versioning with Git

    Versioning with Git

    Mendix 9 introduced Git versioning as an alternative to Subversion (SVN) versioning. Since then, the Git implementation…

    7 条评论
  • 2024 Highlights and Lowlights

    2024 Highlights and Lowlights

    It's the end of the year, so it's time to review the highlights and lowlights. 2024 was a rollercoaster ride for my…

    6 条评论
  • Feature Flash Advent Calendar Recap

    Feature Flash Advent Calendar Recap

    Welcome to the recap of the Mendix Ignite Feature Flash Advent Calendar 2024. For 24 days, I have featured the…

    4 条评论
  • Nanoflow VS Microflow when to use which and why?

    Nanoflow VS Microflow when to use which and why?

    Nanoflows versus Microflows: when to use which and why? Or perhaps even a combination of the two. Mendix…

    16 条评论
  • Capture The Flag Lessons Learned

    Capture The Flag Lessons Learned

    Capture the Flag (CTF) at Mendix Headquarters was awesome. The vibe, the challenges, the organisation, and the lessons…

    6 条评论
  • Passwordless login

    Passwordless login

    Passwords are a necessary evil. They protect your applications and are half of a puzzle that authenticates us to access…

    9 条评论
  • Mendix branching strategies

    Mendix branching strategies

    Branching and how to go about it is a frequently asked question in every Mendix project I have participated in. Mendix…

    12 条评论
  • From high-coder to low-coder

    From high-coder to low-coder

    I speak with many developers in the Mendix Scene, and rarely do I meet others who made the same journey as I did:…

    6 条评论

社区洞察

其他会员也浏览了