Then the dealer gives itself two cards # Noneįeatures/dealer.feature:3 Deal initial cardsĠ steps passed, 0 failed, 0 skipped, 3 undefined Scenario: Deal initial cards # features/dealer.feature:3 Now to see how Behave works, simply open a terminal in the root directory of your code and run the following command:įeature: The dealer for the game of 21 # features/dealer.feature:1 You should strive for this when writing behavioral tests because they are easily readable by anyone working in the code base. Notice that the three phases read like a normal English sentence. Here’s how this is translated into a Behave test: Scenario: Deal initial cards For this test, our state is a new dealer object, the action is the round starting, and the expected outcome is that the dealer has two cards. “Given” initializes a state, “When” describes an action, and “Then” states the expected outcome. The word Behave uses to define a test is “Scenario”, so go ahead and add the following line: Scenario: Deal initial cardsīefore we write more, we need to understand the three phases of a basic Behave test: “Given”, “When”, and “Then”. The first test will be simple - when the round starts, the dealer should deal itself two cards. In a large application, you would have many features. Open dealer.feature and add the following first line: Feature: The dealer for the game of 21 We’ll approach this problem from a test-driven perspective, so instead of jumping to code, we’ll start with the tests.
0 Comments
Leave a Reply. |