Mars Rover – Refactoring Kata

Posted by

On several occasions, I have used the Mars Rover challenge to train developers on TDD principles. This time, I am using it as a refactoring Kata!

I submitted the initial code on my GitHub repository that covers all the cases except the edge ones. But, the code I’ve written is in bad shape.

How to solve this Kata?

To solve this kata, you have two tasks to do. Firstly, you must refactor the code and ensure it follows the clean code principles. Secondly, you must write code covering the Mars Rover’s edge cases.

Note: Before proceeding, make sure to fork the repository to your GitHub account.

Task 1: Code Refactoring

  1. Start by writing unit tests to cover all the cases of this challenge. This is a crucial step to ensure that the refactoring doesn’t break your code. In total, you should write around 12 unit tests to have good coverage of the code.
  2. Now it’s time to refactor the existing code. While doing that:
    1. Think of the design patterns that might help improve the code
    2. Apply some of the S.O.L.I.D principles to have clean classes and methods

Task 2: Missing Features

There is a missing feature with my code. Currently, the rover can move out of the plateau if given the wrong commands. It’s your task to write the code that handles this case. The rover’s position should not be modified if the next spot is outside the plateau.


This kata is relatively easy, but I think it is an excellent first step into the world of code refactoring and writing tests for existing code.

Looking forward to your feedback…

References & Links

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s