If you’ve ever sold industrial automation gear, you know a dud controller can turn a client’s production line from “running smooth” to “why did we even invest in this?” in 24 hours. That’s why when I’m prepping to ship a controller, I don’t wait for a client’s first bad log to catch a bug—I unit test every part of it, long before it hits the factory floor. If you’re a dev, an automation engineer, or someone who just cares that your control hardware actually works, this is the no-BS guide to unit testing controllers that I’ve refined over 10 years of selling these things. No jargon, no stuffy textbooks, just real-world stuff that’s saved my team hundreds of hours of callback tickets. Controller

First, let’s get one thing straight: unit testing for a controller isn’t like testing a website’s checkout flow. Controllers live in the real world—they talk to sensors, trigger motors, and make split-second decisions that actually move physical parts. So I don’t waste time testing abstract “units” in a vacuum; I test every discrete function that matters, one at a time, like I’m picking apart a puzzle to make sure none of the pieces are wonky. That’s the key difference between unit testing for software and unit testing for the hardware/software combo that’s a controller.
Let’s break this down step by step, starting with the easiest (and most important) stuff first. First up: test the core logic without hooking anything to the controller. My team calls this the “headless test” because we run the controller’s firmware on our laptops first, no physical wires attached. For example, if my controller has a safety logic function that stops a conveyor if a light curtain triggers, I don’t wait to plug in the light curtain to test that. I write mock inputs: I feed the controller a “virtual” signal that mimics what the light curtain would send if something crosses it, and then I check if the output is what it’s supposed to be—no conveyor run, no error messages.
Wait, why mock inputs? Because real-world sensors can be finicky—they drift, they send random noise, they take time to connect. If I test only with the physical light curtain, I might miss a bug where the safety logic only works when the light curtain sends a clean, perfect signal. Mock inputs let me throw garbage at the controller on purpose: like a half-signal, a too-short pulse, or even a signal that’s way out of range (like 10 volts when it’s supposed to be 0-5). If the controller crashes or sends the wrong output when I feed it garbage, that’s a bug I fix before it ever gets to a client. Last year we had a client who swore their controller was bad because it cut off a motor mid-run for no reason. Turns out it was a stray electrical signal from a nearby welding robot, and the controller’s logic didn’t have a filter to ignore that noise. If we’d tested with mocks, we would’ve caught that filter gap before shipping.
Next step: test the I/O channels individually. Once we’re happy with the core logic, we hook up a simple test rig to check every input and output port on the controller—no big sensors or motors, just cheap test gear. For input ports, we use a power supply to send known voltages or currents (or digital signals, like 0 or 1) and make sure the controller reads them correctly. For output ports, we connect a multimeter to check if the controller sends the exact voltage/current it’s supposed to when we trigger a function. This might sound tedious, but it’s how we caught a weird bug a while back: our batch of controllers had one input port that flipped high when it was supposed to be low, and it only showed up when we tested multiple ports at once. If I’d skipped this step, a client’s motor wouldn’t turn off when it was supposed to, and I’d be driving 3 hours to fix it instead of shipping a fixed unit.
Don’t forget edge cases, either. Controllers don’t just handle normal, everyday inputs—they handle the weird stuff that happens when no one’s looking. Like, what if you lose power mid-sequence? What if a sensor sends a signal that’s at the absolute limit of what the controller can read (like 5.1 volts when the spec says max is 5)? What if you run the controller 10,000 times in a row to make sure it doesn’t slow down or glitch? We call these “stress tests” and “corner case tests,” and they’ve saved us from a lot of panic. Once, we had a client’s controller reset itself every time their line ran two shifts straight. Turns out the firmware had a memory leak that only showed up after 8 hours of non-stop operation—something we caught by running our test rig for 12 hours straight, no breaks.
Now, here’s something most new controller suppliers skip: test the communication protocols. Most controllers don’t work alone—they talk to HMI screens, other controllers, or cloud servers. If your controller can’t send data to where it needs to go, it’s useless, no matter how good its core logic is. So we test every protocol we support: Modbus, Ethernet/IP, whatever. For example, if a controller’s supposed to send a production count to an HMI, we run a test that sends 1,000 counts back to back and make sure none get dropped. We also test what happens if the connection drops: does the controller hold onto its data until the connection comes back? Does it send an error alert? If not, that’s a bug. A few years back, a small bakery ordered 20 of our controllers to run their cake decorating lines. They told us later that the communication test caught a missing error flag that would’ve made them lose track of 100 cakes a week—stuff that would’ve cost them thousands.
Wait, let’s talk about common mistakes I see other suppliers make. A lot of people treat unit testing like a checkbox: write a test, hit run, move on. No. You need to make these tests automated, so every time we update the firmware, we run them all in 10 minutes, and if any test fails, we don’t ship the code. That’s not just for us—it’s for the client, too. If a new firmware update breaks something that used to work, automated tests catch it before it gets to a customer. Another mistake: testing only the happy path. No one runs a production line perfectly 100% of the time. If you only test when all sensors work and all signals are clean, you’re setting yourself up for callbacks. I can’t stress that enough: unit testing isn’t about proving your controller works when everything is ideal—it’s about proving it works when things go wrong.
Let me give you a concrete example of how this all comes together, from a recent client. A car parts manufacturer reached out last quarter because their old controller kept failing safety tests every month. They switched to ours, and here’s how our unit testing would’ve fixed their old problem. Their safety function requires two sensors to confirm a door is closed before the press runs. Their old controller only checked one sensor, so if that sensor glitched, the press would run with the door open. Our unit tests would’ve: 1) Mocked both sensors to send “door open” and “door closed” signals, confirmed the press only runs when both are closed. 2) Fed a fake glitch to one sensor, confirmed the controller doesn’t run the press and sends an alert. 3) Tested the I/O port for that safety signal to make sure it didn’t flip. 4) Tested the communication to their HMI to make sure the error showed up on the screen. That’s the difference between a controller that works and a controller that fails.
Now, for the people reading this who are buying controllers—not selling them. A quick tip: don’t just ask suppliers “do you unit test your controllers?” Ask them what exactly they test. Do they test edge cases? Do they automate the tests? Do they test communication? If a supplier can’t give you specific examples of the bugs they caught in unit tests, that’s a red flag. We’ve had clients tell us they once got a controller that worked in the lab but died after 2 weeks on their line—stuff that never would’ve happened if proper unit testing was done.

At the end of the day, unit testing isn’t a fancy luxury. It’s the foundation of a controller that actually does what it’s supposed to, when it’s supposed to, even when things go sideways. I’ve built my business on this—no cutting corners on testing, no shipping “good enough” units. If you’re looking for a controller supplier that takes testing seriously, or you have questions about what goes into making a controller reliable, feel free to reach out. We’re always happy to walk through our process, or help you pick the right controller for your application.
Stepper Motor References
- Industrial Automation Handbook, 5th Edition, McGraw-Hill
- Unit Testing for Embedded Systems, Second Edition, Addison-Wesley Professional
- Automation Standards for Safety Controllers, International Society of Automation (ISA)
Hangzhou ANG Drive Co., Ltd.
As one of the most professional controller manufacturers and suppliers in China, we’re featured by quality products and good service. Please rest assured to wholesale custom made controller from our factory. Good service and quality products are available.
Address: No.185, Jincheng Rd., Hangzhou 311202, China
E-mail: export2@angdrive.com
WebSite: https://www.anjodrive.com/