As SCADA, MES, and HMI projects become larger, more complicated, and interact with many different systems, the time has come to start thinking about adopting TDD and Unit Tests into your development lifecycle.
What is a Unit Test?
A Unit Test is simply a set of code that tests another set of code. Usually, Unit Tests are used in pair with additional DevOps tools to automate the running of these tests and to prevent deployments if one or more of the tests are unsuccessful.
What is TDD?
Test-Driven Development or TDD is a programming concept in which you write the Unit Tests for your project before you write the code that is needed to run them. An example of this would be, knowing that you need to add two numbers in your program. So you would write a test named something like test_add().
You would then run this test, and it would fail because you haven’t written code for it yet. Your next step would be to write the minimum amount of code needed to make this test succeed.
If you were to now run that same test above, you would get a successful test result. You can now go back into your add() function and refactor it by any means necessary but to still fall into good coding practices.
Downsides to Unit Tests and TDD
More time is usually needed to write good tests. This is one of the biggest arguments against Unit Tests and TDD but it should not be. Yes, more time is being spent upfront with the design of tests and functions but it also allows you to easily test if new code that is added breaks existing code by simply running a test. This makes it great for entry-level developers because it is easier for an upper-level developer to know at a moment’s notice if code is not working correctly.
Culture change. TDD is not a one developer task, the entire team must utilize this method for it to be completely successful. This is usually a problem because most developers just want to code and worry about “testing” later. This type of attitude will make this methodology pointless.
These examples were very simple and most likely not applicable to a real-world environment, but the concepts are very important, especially with SCADA/MES systems interacting with other systems in the IT realm. One thing you should ask yourself; if your IT level systems are expected to have automated testing attached to them, then why not your SCADA/MES system?