Skip to content

The Gilded Rose Refactoring Kata, adapted for Salesforce Apex

Notifications You must be signed in to change notification settings

stephanspiegel/apex-gilded-rose-kata

Repository files navigation

Gilded Rose Refactoring Kata for Salesforce Apex

What is this?

A code kata is a coding exercise with a focus on learning new skills (as opposed to solving a specific problem). The Gilded Rose Refactoring Kata started as an exercise in C# , and has been ported to many other programming languages. For more on the history of this kata, see the Readme for Emily Bache's project.

The aim of this kata is to learn how to put an existing code base under unit tests and then refactor it in small steps, as opposed to solving the problem in a re-write from scratch.

The problem statement of this kata reads a lot like a typical scenario one would encounter in a Salesforce org, and the existing code reminds me of many poorly implemented classes I've encountered in various orgs (some of which I may or may not have written). It seems particularly suited for developers wanting to expand their Apex skills, and so this is my Salesforce version of the kata.

Getting Started

You'll most likely want to complete this exercise in a scratch org.

Prerequisites

  • The sfdx cli
  • An org with Dev Hub enabled
  • git

Project setup

  1. Clone the repository
    git clone https://github.com/stephanspiegel/apex-gilded-rose-kata.git
  1. Change into project directory
    cd apex-gilded-rose-kata
  1. Spin up a scratch org
    sfdx force:org:create --definitionfile config/project-scratch-def.json --durationdays 30 --setalias gilded-rose -s

If you don't have your Dev Hub configured as a default, you may need to run this first:

    sfdx config:set defaultdevhubusername=[yourDevHubAlias]
  1. Push the code
    sfdx force:source:push

Now the fun begins!

Suggested steps:

  1. This kata provides one unit test that doesn't pass. Make it pass, then add more unit tests to cover all requirements except for the new functionality.
  2. Taking small steps, refactor the existing code. Make sure the unit tests continue to pass.
  3. Implement the new functionality, along with unit tests to cover it.

About

The Gilded Rose Refactoring Kata, adapted for Salesforce Apex

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages