Unit testing frameworks?

Nineplanets

Member
Join Date
Aug 2015
Location
Munich/Stockholm
Posts
13
Has anyone here come across unit testing frameworks for PLCs/automated system IDE's (like JUnit for Java)?

I've been searching the net, but it seems quite uncommon for doing unit testing in the industry automation world for some reason. Why could this be?
 
We've had this topic recently in german plc forum. For Codesys you can buy an addon which allows you to write automated software tests for your plc program, but I haven't it used for myself:

http://store.codesys.com/codesys-test-manager.html?___store=en&___from_store=default

Automated testing of plc programs are little bit more difficult compared to a PC program, as most plcs don't run under the PC processors. So you'll need an real plc or at least a plc simulator, where you have to upload your program and run your tests. To get the results from the plc, you have to setup a communication to retrieve them.

I've made some tests of how I would do this in Siemens Step7, as this is what I use mostly. To not reinvent the wheel and maybe to reuse some existing tools, I've used googletest as a basis. Step7 has the interfaces that let you control the full process you need for an automated test (adding sourcecode, compiling, upload program, start plc, and retrieve the results).

But I'm still uncertain if unittests help you a lot for plc programming. As most of the blocks you would use in a library for example are rather simple in a plc environment. The complexity comes with the whole system, interacting with external signals, external hardware, network communication and so on. An this is what is not easy to write an automated test for.
 
Hi Thomas, thanks for your reply.

Thanks for the link, will investigate that. I'm specifically running TwinCAT3 (Beckhoff), and as I'm writing my software as I mostly usually would (using OO-patterns), I thought it's well prepared for doing unit tests. My primary purpose would not to be doing tests on a high system level (interfaces using communications out to the fieldbus etc) but rather testing a function block (class) for function block, and making sure the FBs return what they are supposed to return given certain prerequisites.

I guess the commercial/open source options are limited. I might just start a separate PLC project that uses the TwinCAT3 projects (as libraries), and then create a test suite which instantiates the FBs, provides them with some data and asserts that the output of the FBs (either directly or by calling their methods) give what they are supposed to.

Maybe someone has some experience in doing so here for TwinCAT3/CodeSys and can chime in with some experience/good advice?
 
I guess the commercial/open source options are limited. I might just start a separate PLC project that uses the TwinCAT3 projects (as libraries), and then create a test suite which instantiates the FBs, provides them with some data and asserts that the output of the FBs (either directly or by calling their methods) give what they are supposed to.

The basic setup to create an automated test framework is relatively easy. But if you have all tools together, there will got many hours into the project, and 1500€ for the codesysframework maybe cheaper (and better?). But if you do it on your own, you have the advantage that you can expand the framework for whatever you need.

My testing "test framework" does it in the way you described.
I've got a for example a testfunction which adds two integers,
and one or more test descriptions to make some tests if the function works. This is a little bit similar to googletest:
Code:
TEST(AdditionTest, BasicTest) {
    VAR
        retval : INT;
    END_VAR

    BEGIN
        retval := FCADD(IN1 := 1, IN2 := 2);
        EXPECT_EQ_I(IN1 := 3, IN2 := retval);
    END
}

TEST(NegativeTest, BasicTest2) {
    VAR
        retval2 : INT;
    END_VAR

    BEGIN
        retval2 := FCADD(IN1 := -100, IN2 := -10);
        EXPECT_EQ_I(IN1 := -110, IN2 := retval2);
    END
}
I've written a small python script which parses the testdiscription, and builds a function block for each testcase, and a main-function which calls them one after each other.

EXPECT_EQ_I is a test function which makes the test, and puts the result of the test into a big string array, which I readout at the end.

With my Step7 environment it takes about 30 seconds for a complete testrun. Click "start test", build test, compile, download and get the results.

It all depends if you can do all steps automated via an external interface. If it would take to many manual steps, I wouldn't use it. With Siemens TIA portal for example, you can't do this.
 

Similar Topics

Hi all! Just wanted to tell everyone that I've created an unit testing framework for TwinCAT3. It's completely free, open-source and licensed...
Replies
1
Views
2,615
I want to test a small cabinet that includes a POINT IO unit type 1734-AENT. How can I test this unit if I don't have a PLC?
Replies
3
Views
1,627
I'm fairly new to Rockwell software, I've had some basic training in the past but nothing too advanced. My company and I use Reliable products for...
Replies
11
Views
318
Hello, all, total noob here hoping for a little guidance. I bought a new piece of printing equipment that has a Mitsubishi PLC and this Data...
Replies
7
Views
174
This application has a motor with encoder feedback that drives a linear actuator that moves in/out, and is at roughly 45 degs from horiz. As the...
Replies
19
Views
1,362
Back
Top Bottom