Sonntag, 3. Februar 2013

Test Driven Statechart Development with Yakindu SCT

In test driven development, the developer creates automated unit tests before writing the implementation logic. These unit tests define the behavior of a particular piece of code using assertions and are very important to avoid regression when refactoring code.

Test driven development can and should also be used in the context of model-driven development. Since Yakindu statecharts provide an interface definition for every statechart model, it is possible to write unit tests against these interfaces before creating the implementing statechart model. We are currently developing a testing framework for test driven statechart development, called SCTUnit.

SCTUnit is a unit testing framework for Yakindu Statechart Tools. It allows test driven development of statechart models on the semantic level of statecharts.

Let's assume that we want to create a software to control a safe. The safe can be opened when the user enters the right three-digit number (375). It should also be possible to reset the entered numbers. Based on these requirement, we can derive the following statechart interface:
Since we want to develop the implementation in a test-driven way, we first create a unit test using SCTUnit.

SCTUnit supports a lot of assertions including checks for active states and comparing values of variables. For simplicity, we only use a subset of the assertions in this example.

A really cool feature of SCTUnit is that you can execute the tests like a JUnit test. An interpreter evaluates the unit test and executes the statechart model. The result is shown in the JUnit view. As we can see, testSafeOpenSuccess fails.

Let's create an implementation statechart to fix this.... the test suite again....

...much better.... ;-)

But SCTUnit can do a lot more for you. Based on the specified SCTUnit test suite, the framework generates JUnit tests to test the generated Java statechart as well as GTests for the generated C code.

There is still a lot of work to do until we will releae version 1.0 of SCTUnit. Feedback or feature request can be provided via our community forum.

Keine Kommentare:

Kommentar veröffentlichen