</>

Technology

Cucumber

Difficulty

Advanced

Interview Question

Your Cucumber feature file has grown to 80 scenarios in one file. A team member wants to keep it as-is. How do you convince them to split it and how do you do it?

Answer

Splitting an 80-Scenario Feature File

Why 80 Scenarios in One File Is a Problem

Present these points to the team member:

1. Readability
CODE
login.feature with 80 scenarios:
  - Takes 5 minutes to scroll through
  - Can''t tell what''s covered without reading everything
  - New team member has to read 1000+ lines to understand login

vs 8 files × 10 scenarios:
  - File name tells you the focus: login_2fa.feature
  - Open, scan 10 scenarios, done in 30 seconds
2. Merge Conflicts
CODE
With 80 scenarios in one file:
  - 5 QAs working on login tests → 5 people editing same file
  - Every PR has a merge conflict in login.feature

With split files:
  - QA1 edits login_valid.feature, QA2 edits login_2fa.feature
  - Zero merge conflicts
3. Execution Granularity
CODE
Tag @smoke to first 5 scenarios in the file → fragile (line-number dependent)
Tag @smoke on login_happy_path.feature → robust, file-level control
4. Parallel Execution Efficiency
CODE
Cucumber can parallelize at feature file level
1 file × 80 scenarios = serial within the file
8 files × 10 scenarios each = 8x parallel potential

How to Split

Original monolithic file:

CODE
login.feature (80 scenarios):
  Scenario 1-10:  Valid login
  Scenario 11-20: Invalid credentials
  Scenario 21-30: Password reset
  Scenario 31-40: 2FA/OTP
  Scenario 41-50: Session management
  Scenario 51-60: Remember me
  Scenario 61-70: Account lockout
  Scenario 71-80: Social login

After split:

CODE
features/
  login/
    login_valid_credentials.feature      (10 scenarios) @smoke @P1
    login_invalid_credentials.feature    (10 scenarios) @regression @P2
    login_password_reset.feature         (10 scenarios) @regression @P2
    login_two_factor_auth.feature        (10 scenarios) @regression @P1
    login_session_management.feature     (10 scenarios) @regression @P2
    login_remember_me.feature            (10 scenarios) @regression @P3
    login_account_lockout.feature        (10 scenarios) @regression @P2
    login_social_oauth.feature           (10 scenarios) @regression @P3

Naming Convention

CODE
<module>_<sub-feature>_<scenario-type>.feature

login_valid_credentials.feature
login_error_messages.feature
checkout_payment_credit_card.feature
checkout_payment_paypal.feature
cart_add_remove_items.feature
cart_coupon_codes.feature

Directory Structure

CODE
features/
  auth/
    login_valid.feature
    login_invalid.feature
    login_2fa.feature
    registration.feature
    password_reset.feature
  product/
    search.feature
    filter.feature
    product_detail.feature
  cart/
    add_to_cart.feature
    coupon.feature
    cart_persistence.feature
  checkout/
    payment_card.feature
    payment_paypal.feature
    shipping.feature
  admin/
    user_management.feature
    product_management.feature

How to Split Without Disrupting CI

Bash
# Step 1: Create directory structure
mkdir -p src/test/resources/features/auth

# Step 2: Copy relevant scenarios to new files (keep original)
# Step 3: Run both original + new files - verify same results
# Step 4: Delete original file
# Step 5: Update any hardcoded references to old filename

Follow AutomateQA

Related Topics