Another Real World BDD Example (#2)

This is my second real world BDD example that we've written in the past here at Clearly Agile. I've been given permission to share this piece of code from the client.

My previous example you can view here, which is around languages.

In this example, we have a scenario where a user can create something called a "Project" and it has to have a correct "Open Date". Open Date is when the Project is complete and it's calculated off a collection of Tasks. 

When creating a "Project", you must associate an existing "Timeline." Think of a Timeline of something like a Gantt chart. A "Timeline" has Phases which have Milestones which have Tasks that have due dates and dependent tasks.  There is final "Open Date" to the timeline which should land on a specified date. This is the date we want to validate.

So you can see this is somewhat involved. The system must calculate dates on the timeline and check the tasks and dependent tasks and then determine the completion date. 

So in this example, we are going to BDD the feature of creating a Project, associating a Timeline and making sure the completion date is correct..

Step 1: The Feature

So using SpecFlow in .NET we'll create a Feature file and give it the contents of the User Story.

Feature: Creating Projects
    As a Project Owner, I want to create a new project
    so that can get a timeline and estimated open date for my project and start tracking it.

Step 2: The Background

Now we'll create something called a Background in BDD. This is something that applies to all the other Scenarios that run later. Think of this as a setup, or a prerequisite before we can run our Scenarios and test them.

This Background is big. We want to create a project, which requires an existing Timeline. This Timeline has Phases, Milestones, and Tasks. 

So we make sure all that is in place before hand with the Background:

Background:
    Given the following Companies exist:
        | Name                    |
        | Butler Holdings         |
        | James P. Johnson Realty |
    And the following Contacts exist:
        | FirstName | LastName   | Email                    | PrimaryContactForCompany |
        | Velma     | Williams   | velma@mysterymachine.org | Butler Holdings          |
        | Fred      | Flintstone | fred@bedrock.us          | James P. Johnson Realty  |
        | Judy      | Jetson     | judyj@skypoint.com       |                          |
        
    And the following Concepts exist:
        | Name                   |
        | Burger Joint           |
        | Beer Bar               |
        | Laser Treatment Center |

    And the following Project Statuses exist:
        | Name     |
        | Active   |
        | Archived |
        | Dead     |         
        
    And a Master Timeline named "New Location" exists

    And the Master Timeline "New Location" has the following phases:
        | Name             |
        | Deal Negotiation |
        | Due Diligence    |
        | Plans Generation |
        | Permitting       |
        | Construction     |

    And the Master Timeline "New Location" has the following milestones:
        | Phase            | Name                                                  | IsVisibleOnReport | IsTrackedAgainstCommitmentDate | IsOpenMilestone |
        | Deal Negotiation | Letter of Intent (LOI)                                | false             | false                          | false           |
        | Deal Negotiation | Preliminary Floorplan                                 | false             | false                          | false           |
        | Deal Negotiation | Estimate Project Parameters                           | false             | false                          | false           |
        | Deal Negotiation | 1st Pass - Site Approval                              | true              | false                          | false           |
        | Due Diligence    | Signed LOI                                            | false             | false                          | false           |
        | Due Diligence    | Contractor WalkThrough                                | false             | false                          | false           |
        | Due Diligence    | Detailed Project Parameters                           | false             | false                          | false           |
        | Due Diligence    | 2nd Pass - Execution Copies of Lease Prepared         | true              | false                          | false           |
        | Plans Generation | Lease Execution                                       | true              | true                           | false           |
        | Plans Generation | Floorplan Layout and Approval                         | true              | false                          | false           |
        | Plans Generation | Full ASMEP (and Civil if applicable) Plans Generation | false             | false                          | false           |
        | Permitting       | Submit for Permits                                    | false             | false                          | false           |
        | Permitting       | Permit Available                                      | true              | false                          | false           |
        | Permitting       | 3rd Pass - Approved for Construction Spend            | true              | false                          | false           |
        | Construction     | Waive Lease Contingencies                             | false             | false                          | false           |
        | Construction     | Construction Start                                    | false             | false                          | false           |
        | Construction     | Construction Complete                                 | true              | false                          | false           |
        | Construction     | Unit Opening                                          | true              | true                           | true            |

    And the Master Timeline "New Location" has the following tasks:
        | Milestone                                             | Task                                                                      | ParentTaskMilestone                                   | ParentTask                                                            | DaysToComplete | AutoAssignToProjectOwner | IsMilestoneCloseOut |
        | Letter of Intent (LOI)                                | Determine if the site pad ready, inline, or as-is                         |                                                       |                                                                       | 1              | true                     | false               |
        | Letter of Intent (LOI)                                | Review the deal terms                                                     | Letter of Intent (LOI)                                | Determine if the site pad ready, inline, or as-is                     | 1              | true                     | true                |
        | Preliminary Floorplan                                 | Request a cadd file of the site/space                                     | Letter of Intent (LOI)                                | Determine if the site pad ready, inline, or as-is                     | 2              | true                     | false               |
        | Preliminary Floorplan                                 | Create a preliminary space/block or site plan                             | Letter of Intent (LOI)                                | Determine if the site pad ready, inline, or as-is                     | 10             | true                     | false               |
        | Preliminary Floorplan                                 | Begin project due diligence with the Broker/Dev/Seller/LL                 | Letter of Intent (LOI)                                | Review the deal terms                                                 | 10             | true                     | true                |
        | Estimate Project Parameters                           | Assemble an estimate of project Costs                                     | Letter of Intent (LOI)                                | Review the deal terms                                                 | 7              | true                     | false               |
        | Estimate Project Parameters                           | Assemble a project schedule                                               | Letter of Intent (LOI)                                | Review the deal terms                                                 | 7              | true                     | false               |
        | Estimate Project Parameters                           | Run a Return on Investment                                                | Estimate Project Parameters                           | Assemble an estimate of project Costs                                 | 5              | true                     | true                |
        | 1st Pass - Site Approval                              | Assemble project information and distribute                               | Estimate Project Parameters                           | Run a Return on Investment                                            | 5              | false                    | false               |
        | 1st Pass - Site Approval                              | Present the information to the Department for Site Approval               | 1st Pass - Site Approval                              | Assemble project information and distribute                           | 3              | true                     | true                |
        | Signed LOI                                            | Execution of the Letter of Intent                                         | 1st Pass - Site Approval                              | Present the information to the Department for Site Approval           | 1              | true                     | false               |
        | Signed LOI                                            | Review and Comments by Attorney on Lease Draft                            | Signed LOI                                            | Execution of the Letter of Intent                                     | 10             | true                     | true                |
        | Contractor WalkThrough                                | Choose a licensed contractor with experience                              | Signed LOI                                            | Execution of the Letter of Intent                        | 5              | true                     | false               |
        | Contractor WalkThrough                                | Schedule a walkthrough of the space                                       | Contractor WalkThrough                                | Choose a licensed contractor with experience                          | 5              | true                     | true                |
        | Detailed Project Parameters                           | Refine the project costs                                                  | Contractor WalkThrough                                | Schedule a walkthrough of the space                                   | 5              | true                     | false               |
        | Detailed Project Parameters                           | Refine the project schedule                                               | Contractor WalkThrough                                | Schedule a walkthrough of the space                                   | 7              | true                     | false               |
        | Detailed Project Parameters                           | Request and Review ESA, Geotech, Declarations, Restrictions, etc          | Signed LOI                                            | Execution of the Letter of Intent                                     | 17             | true                     | false               |
        | Detailed Project Parameters                           | Run a Return on Investment                                                | Detailed Project Parameters                           | Refine the project schedule                                           | 5              | true                     | true                |
        | 2nd Pass - Execution Copies of Lease Prepared         | Assemble detailed project information and distribute                      | Detailed Project Parameters                           | Run a Return on Investment                                            | 5              | false                    | false               |
        | 2nd Pass - Execution Copies of Lease Prepared         | Create execution copies of the lease                                      | 2nd Pass - Execution Copies of Lease Prepared         | Assemble detailed project information and distribute                  | 1              | true                     | true                |
        | Lease Execution                                       | Execution of the Lease                                                    | 2nd Pass - Execution Copies of Lease Prepared         | Create execution copies of the lease                                  | 7              | true                     | false               |
        | Lease Execution                                       | Production of the Lease Abstract                                          | Lease Execution                                       | Execution of the Lease                                                | 5              | true                     | false               |
        | Lease Execution                                       | Complete a Lease Obligation Worksheet for timing                          | Lease Execution                                       | Production of the Lease Abstract                                      | 3              | true                     | true                |
        | Floorplan Layout and Approval                         | Transmit Preliminary floorplan to the Architect and/or engineer           | Lease Execution                                       | Execution of the Lease                                      | 8              | true                     | false               |
        | Floorplan Layout and Approval                         | Architect produces detailed floorplan                                     | Floorplan Layout and Approval                         | Transmit Preliminary floorplan to the Architect and/or engineer       | 5              | true                     | false               |
        | Floorplan Layout and Approval                         | Department Review of Floorplan                                            | Floorplan Layout and Approval                         | Architect produces detailed floorplan                                 | 3              | true                     | false               |
        | Floorplan Layout and Approval                         | Approval of Floorplan                                                     | Floorplan Layout and Approval                         | Department Review of Floorplan                                        | 1              | true                     | true                |
        | Full ASMEP (and Civil if applicable) Plans Generation | Production of full construction plans, monitoring fixture count           | Floorplan Layout and Approval                         | Approval of Floorplan                                                 | 30             | false                    | false               |
        | Full ASMEP (and Civil if applicable) Plans Generation | Run a Return on Investment                                                | Full ASMEP (and Civil if applicable) Plans Generation | Production of full construction plans, monitoring fixture count       | 5              | true                     | true                |
        | Submit for Permits                                    | Determine if expediting services are required                             | Full ASMEP (and Civil if applicable) Plans Generation | Production of full construction plans, monitoring fixture count       | 6              | true                     | false               |
        | Submit for Permits                                    | Submit to all agencies and to the LL for Approval                         | Submit for Permits                                    | Determine if expediting services are required                         | 5              | true                     | false               |
        | Submit for Permits                                    | Distribute plans for bidding                                              | Submit for Permits                                    | Determine if expediting services are required                         | 5              | true                     | false               |
        | Submit for Permits                                    | Address Comments and Resubmit                                             | Submit for Permits                                    | Distribute plans for bidding                                          | 30             | true                     | true                |
        | Permit Available                                      | Produce a detailed accounting of funds spent and upcoming costs           | Submit for Permits                                    | Address Comments and Resubmit                                         | 5              | true                     | false               |
        | Permit Available                                      | Request a project schedule from the GC                                    | Permit Available                                      | Produce a detailed accounting of funds spent and upcoming costs       | 5              | true                     | false               |
        | Permit Available                                      | Run a Return on Investment                                                | Permit Available                                      | Request a project schedule from the GC                                | 5              | true                     | true                |
        | 3rd Pass - Approved for Construction Spend            | Assemble finalized project information and distribute                     | Permit Available                                      | Run a Return on Investment                                            | 5              | false                    | false               |
        | 3rd Pass - Approved for Construction Spend            | Present the information to the Department for construction spend approval | 3rd Pass - Approved for Construction Spend            | Assemble finalized project information and distribute                 | 5              | true                     | true                |
        | Waive Lease Contingencies                             | Assess Risks associated with contingencies waiver                         | 3rd Pass - Approved for Construction Spend            | Assemble finalized project information and distribute                 | 5              | true                     | false               |
        | Waive Lease Contingencies                             | Request a PreConstruction Meeting with the GC, Arch, and Municipality     | 3rd Pass - Approved for Construction Spend            | Assemble finalized project information and distribute                 | 5              | true                     | false               |
        | Waive Lease Contingencies                             | Pull Permit                                                               | Waive Lease Contingencies                             | Request a PreConstruction Meeting with the GC, Arch, and Municipality | 1              | true                     | true                |
        | Construction Start                                    | Review Project Schedule in detail with the GC                             | 3rd Pass - Approved for Construction Spend            | Assemble finalized project information and distribute                 | 6              | true                     | false               |
        | Construction Start                                    | Monitor Construction Progress                                             | Construction Start                                    | Review Project Schedule in detail with the GC                         | 80             | true                     | false               |
        | Construction Start                                    | Create Punchlist                                                          | Construction Start                                    | Monitor Construction Progress                                         | 5              | true                     | true                |
        | Construction Complete                                 | Reconcile Project costs and change orders                                 | Construction Start                                    | Monitor Construction Progress                                         | 10             | true                     | false               |
        | Construction Complete                                 | Complete all Punchlist Items with GC                                      | Construction Start                                    | Monitor Construction Progress                                         | 10             | true                     | false               |
        | Construction Complete                                 | Start Training                                                            | Construction Complete                                 | Complete all Punchlist Items with GC                                  | 5              | true                     | true                |
        | Unit Opening                                          | Complete Training                                                         | Construction Complete                                 | Start Training                                                        | 5              | true                     | false               |
        | Unit Opening                                          | Prepare Facilities Maintenance Guide                                      | Construction Complete                                 | Complete all Punchlist Items with GC                                  | 10             | true                     | false               |
        | Unit Opening                                          | Opening Event                                                             | Unit Opening                                          | Complete Training                                                     | 1              | true                     | true                |

Phew, that's a lot but you know what. If we ever break the business logic on how we calculate the dates, we'll know immediately!

Now that we have our background in place, we can create our Scenarios.

Step 3 - Scenarios

Scenario 1: Create a new Project, given the timeline above

Scenario Outline: Create a new Project
    Given I am logged in as a "Client Administrator"
    When I create a Project "<Name>" for Concept "<Concept>" and Company "<Company>" using the Timeline "<Timeline>" and starting on "<StartDate>" with the Milestone "<StartingMilestone>" and Task "<StartingTask>"
    Then a Project "<Name>" should be created with an Estimated Open Date of "<EstimatedOpenDate>" and "<OperatingWeeks>" Operating Weeks

    Examples:
    | Concept      | Name        | Company                 | Timeline     | StartingMilestone      | StartingTask                                      | StartDate  | EstimatedOpenDate | OperatingWeeks |
    | Burger Joint | Tampa, FL   | Butler Holdings         | New Location | Letter of Intent (LOI) | Determine if the site pad ready, inline, or as-is | 11/14/2016 | 8/13/2017         | 20             |
    | Burger Joint | Chicago, IL | Butler Holdings         | New Location | Letter of Intent (LOI) | Determine if the site pad ready, inline, or as-is | 2/15/2017  | 11/14/2017        | 6              |
    | Burger Joint | Orlando, FL | James P. Johnson Realty | New Location | Letter of Intent (LOI) | Determine if the site pad ready, inline, or as-is | 7/4/2017   | 4/2/2018          | 39             |

You can see from the example above. Our business user has provided us valid examples of what the system should calculate. We can now write code to make this happen.

Scenario 2: You cannot complete a Task before its Parent is Completed

Scenario: Cannot Complete a Task Before Parent is Completed
    Given I am logged in as a "Client Administrator"
    And the following Project exists:
     | Concept      | Name        | Company                 | Timeline     | StartingMilestone      | StartingTask                                      | StartDate  |
     | Burger Joint | Tampa, FL   | Butler Holdings         | New Location | Letter of Intent (LOI) | Determine if the site pad ready, inline, or as-is | 1/1/2016   |
    And the Task "Review and Comments by Attorney on Lease Draft" for Milestone "Signed LOI" was just completed on "4/12/2016"
    When I try to complete Task "Refine the project costs" on Milestone "Detailed Project Parameters"
    Then The Task should not be updated
    And I should see the validation error message "Task cannot be completed until parent task is completed" 

We can continue to build out various Scenarios given the Timeline we have above and make sure all the various calculations work. 

Hope that was of help. If you want to try some TDD or BDD, look into taking our Agile Engineering class.  We partner with the Braintrust Group. If you call them up, let them know we sent ya!