Connecting the dots: BDD, TDD, Use Cases, Architecture and Modular Design

In this episode, we start creating the previously shown Feed feature, by establishing well-defined requirements to guide us in the upcoming development phase.

Learning Outcomes

Description

The feature or system requirements hold the foundation that our code is going to be built on. One of our goals as software developers is to maximize our understanding of how the system should behave to provide maximum value to our customers. A simple, but effective, way to achieve that is to minimize the number of assumptions we’re going to make as developers. We can do so by focusing on communicating effectively with the people responsible for creating the requirements. The goal is to bridge the gap of the technical and business propositions by always aiming to provide the best possible customer experience.

For example, the following requirements don’t bridge that gap. They are vague and susceptible to personal interpretation, instead of having a global understanding of what things are and how they should work.

Story

As a user
I want the app to load the feed
So I can see the feed

Acceptance criteria

Given a user
When the user opens the feed
Then the feed is displayed

Instead of creating assumptions and immediately diving into translating these lousy requirements into code, we can think of these requirements as a “zoomed out” version of the system or perhaps “a puzzle to be solved.” Lousy requirements might show the big picture, but not the essential details. As we ask more and more questions, we should be eliminating more assumptions. Then we can start structuring our ideas better and providing more value to our teams.

The above requirements can be transformed into the following:

Story: Customer requests to see their image feed

Narrative #1

As an online customer
I want the app to automatically load my latest image feed
So I can always enjoy the newest images of my friends

Scenarios (Acceptance criteria)

Given the customer has connectivity
When the customer requests to see the feed
Then the app should display the latest feed from remote
And replace the cache with the new feed

Narrative #2

As an offline customer
I want the app to show the latest saved version of my image feed
So I can always enjoy images of my friends

Scenarios (Acceptance criteria)

Given the customer doesn't have connectivity
And there’s a cached version of the feed
When the customer requests to see the feed
Then the app should display the latest feed saved

Given the customer doesn't have connectivity
And the cache is empty
When the customer requests to see the feed
Then the app should display an error message

We can then start drafting Use Cases, essentially small recipes, for translating the requirements in procedures that we will then turn into code.

Load Feed Use Case

Data (Input):

  • URL

Primary course (happy path):

  1. Execute "Load Feed Items" command with above data.
  2. System downloads data from the URL.
  3. System validates downloaded data.
  4. System creates feed items from valid data.
  5. System delivers feed items.

Invalid data – error course (sad path):

  1. System delivers error.

No connectivity – error course (sad path):

  1. System delivers error.

Load Feed Fallback (Cache) Use Case

Data (Input):

  • Max age

Primary course (happy path):

  1. Execute "Retrieve Feed Items" command with above data.
  2. System fetches feed data from cache.
  3. System creates feed items from cached data.
  4. System delivers feed items.

No cache course (sad path):

  1. System delivers no feed items.

Save Feed Items Use Case

Data (Input):

  • Feed items

Primary course (happy path):

  1. Execute "Save Feed Items" command with above data.
  2. System encodes feed items.
  3. System timestamps the new cache.
  4. System replaces the cache with new data.
  5. System delivers a success message.

Finally, in order to communicate the workflow of the feature to everyone, we can translate the requirements to the following flowchart.

flowchart_colored.png
feed_architecture.png

In the next episode, we’ll start implementing the above requirements, so subscribe now to our Youtube channel and catch free new episodes every week.


We’ve been helping dedicated developers to get from low paying jobs to high tier roles – sometimes in a matter of weeks! To do so, we continuously run and share free market researches on how to improve your skills with Empathy, Integrity, and Economics in mind. If you want to step up in your career, access now our latest research for free.