|
| 1 | +# Python Calculator Example |
| 2 | + |
| 3 | +This is a simple example demonstrating how to use the Cucumber-Behave launcher with Eclipse. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. Python 3.x installed |
| 8 | +2. Behave package installed: |
| 9 | + ```bash |
| 10 | + pip install behave |
| 11 | + ``` |
| 12 | + |
| 13 | +## Running the Example |
| 14 | + |
| 15 | +### From Command Line |
| 16 | + |
| 17 | +```bash |
| 18 | +cd examples/python-calculator |
| 19 | +behave |
| 20 | +``` |
| 21 | + |
| 22 | +### From Eclipse |
| 23 | + |
| 24 | +1. Open Eclipse with Cucumber Eclipse plugin installed |
| 25 | +2. Import this project into Eclipse |
| 26 | +3. Right-click on `features/calculator.feature` |
| 27 | +4. Select "Run As" > "Cucumber-Behave" |
| 28 | +5. In the launch configuration dialog: |
| 29 | + - **Feature Path**: Select the `calculator.feature` file |
| 30 | + - **Working Directory**: Set to the `examples/python-calculator` directory |
| 31 | + - **Python Interpreter**: Use `python` or `python3` depending on your system |
| 32 | + - Click "Run" |
| 33 | + |
| 34 | +## Project Structure |
| 35 | + |
| 36 | +``` |
| 37 | +python-calculator/ |
| 38 | +├── features/ |
| 39 | +│ ├── calculator.feature # Feature file with scenarios |
| 40 | +│ └── steps/ |
| 41 | +│ └── calculator_steps.py # Step definitions |
| 42 | +└── README.md |
| 43 | +``` |
| 44 | + |
| 45 | +## Expected Output |
| 46 | + |
| 47 | +When you run the tests, you should see output indicating that all three scenarios pass: |
| 48 | + |
| 49 | +``` |
| 50 | +Feature: Calculator # features/calculator.feature:1 |
| 51 | +
|
| 52 | + Scenario: Add two numbers # features/calculator.feature:6 |
| 53 | + Given I have a calculator # features/steps/calculator_steps.py:19 |
| 54 | + When I add 2 and 3 # features/steps/calculator_steps.py:23 |
| 55 | + Then the result should be 5 # features/steps/calculator_steps.py:35 |
| 56 | +
|
| 57 | + Scenario: Subtract two numbers # features/calculator.feature:11 |
| 58 | + Given I have a calculator # features/steps/calculator_steps.py:19 |
| 59 | + When I subtract 3 from 5 # features/steps/calculator_steps.py:27 |
| 60 | + Then the result should be 2 # features/steps/calculator_steps.py:35 |
| 61 | +
|
| 62 | + Scenario: Multiply two numbers # features/calculator.feature:16 |
| 63 | + Given I have a calculator # features/steps/calculator_steps.py:19 |
| 64 | + When I multiply 2 by 3 # features/steps/calculator_steps.py:31 |
| 65 | + Then the result should be 6 # features/steps/calculator_steps.py:35 |
| 66 | +
|
| 67 | +3 scenarios (3 passed) |
| 68 | +9 steps (9 passed) |
| 69 | +``` |
0 commit comments