Was ist Behavior-Driven-Development?

Behavior-Driven-Development (or BDD) is a software development technique, that enables collaboration between developers, quality assurance and non-technical participants on a software project.

BDD focuses on creating, through discussions with stakeholders, a clear understanding of the desired software or hardware behavior.

It extends Test-Driven-Development (TDD) by writing test cases in a natural language that non-programmers can read and modify.

It is possible to write tests in the native language and thus obtain the desired behavior of the software or hardware system under test.

Thus the developers are enabled to concentrate less on the technical implementation, but rather on the actual desired behavior of the system under test.

A further advantage is the similarity of requirements and resulting tests.

With HILSTER TestBench it is possible to perform flexible Hardware-in-the-Loop tests besides TDD also with the help of BDD to create, maintain and execute them.

Example

The following example shows a feature with two scenarios to describe the behavior of a controller for a refrigeration machine controller.

                            
    Feature: Temperature controlling of a refrigeration machine
            This feature checks that the temperature of a refrigeration
            machine is controlled according to the requirements.

        Scenario: Cool down
            Given the refrigeration machine controller is running
            When the initial temperature is 0 °C
            Then the refrigeration machine controller is cooling down

        Scenario: Heat up
            Given the refrigeration machine controller is running
            When the initial temperature is -100 °C
            Then the refrigeration machine controller does not cool down
                            
                        

The implementation of each step in python looks like this:

                            
    @htf.given("the refrigeration machine controller is running")
    def start_refrigeration_machine(dut):
        """
        Start the refrigeration.
        """
        dut.start()

    @htf.when(r"the initial temperature is (?P<temperature>\d+) °C")
    def set_temperature(temperature, dut):
        dut.set_temperature(temperature)

    @htf.then("the refrigeration machine controller is cooling down")
    def assert_machine_is_cooling_down(dut):
        htf.assert_true(dut.cooling_down())

    @htf.then("the refrigeration machine controller does not cool down")
    def assert_machine_not_cooling_down(dut):
        htf.assert_false(dut.cooling_down())