BDD(Behavior Driven Development)

What Is BDD?

BDD(Behavior Driven Development) is behavior-driven development.

  • BDD is a development method derived from TDD.
  • It goes one step further than TDD(Test Driven Development) and makes the test cases themselves serve as requirements.

Basic BDD Pattern

BDD writes test cases based on scenarios and does not recommend function-level unit tests. Scenarios should be written at a level that even non-developers can understand.

  • Feature: Specifies the function or responsibility of the test target.
  • Scenario: Describes the situation for the test objective.
  • Given: Sets the values needed to proceed with the scenario.
  • When: Specifies the conditions needed to proceed with the scenario.
  • Then: Specifies the result that must be guaranteed when the scenario is complete.

Example

@Test
fun `aliases for behavior driven development`() {
    // given
    given(calculatorService.add(20.0, 10.0)).willReturn(30.0)

    // when
    val result = calculatorService.add(20.0, 10.0)

    // then
    Assert.assertThat(30.0, CoreMatchers.`is`(result))
}

Kakao if - “If You Have Kotest, Ask About TDD and Go with BDD!”