ATTACK: How To Grok New-To-You Code Via Testing

a graphic image with 1s and 0s
Christian Ayala
Christian Ayala Software Engineer

Many software teams eventually find themselves owning code that they didn’t write. Maybe the charter of the team changed during a reorg. Maybe there was an influx of new engineers. Maybe there was an acquisition. Whatever the case, if a team has never seen a codebase, it will be hard for them to even maintain it, let alone improve or extend it. How do you ramp up a whole team quickly?

Late last year, my team took over Watershed’s financial value mapping system, a codebase of about 16,000 lines that associates emissions factors to each of an organization’s financial accounts. It’s a critical step in the measurement process for most of our customers, as it allows us to estimate Scope 3 emissions from an organization’s expense data. Given that, it was crucial for us to get up to speed, and fast! To do that, we came up with an approach we call an ATTACK. Read on to learn:

Adding Tests To Augment Code Knowledge

ATTACK stands for Adding Tests To Augment Code Knowledge. As contrived as the acronym may be, the idea is simple: by adding tests to an unfamiliar codebase, a team can quickly build code-level familiarity. The approach is widely applicable — it doesn’t matter how junior or senior the engineers are, nor what language the project is written in. And though there’s no shortage of strategies for getting familiar with a new codebase, an ATTACK has two nice benefits:

Implementation

Before embarking on our ATTACK, we agreed on the following three goals:

  1. Become more familiar with surface area: The main thing we wanted was for everyone on the team to feel comfortable working with and talking about the financial value mapping codebase.
  2. Practice writing new kinds of tests: We thought this was a perfect opportunity for engineers to write tests they hadn’t before, such as React component tests or Temporal workflow tests.
  3. Increase test coverage and documentation: Though the existing code already had many tests, we identified some places that could use more.

We knew preparation would be very important for the success of the ATTACK. One member of the team took some time to get familiar with the codebase by reading documentation, playing with the product, and talking to members of the previous owners as necessary. Then, they came up with a list of the important units — like classes, workflows, and functions — and highlighted the ones most in need of testing (detailed, file-level coverage metrics are best, but even a simple count of tests would be a good start).

Once we had this preliminary idea, we ran our ATTACK like a hackathon. To start, that same member of the team gave a quick introduction on the code and areas for improvement, and everyone picked an area to focus on. Then we took two full days to do nothing but add tests. Finally, we each took turns sharing what we’d done and what we’d learned.

And the results? More than a dozen new tests, as well as a handful of code cleanups and refactors. We also added end-to-end tests, which financial value mappings didn’t have before, and gained valuable experience with Playwright as a result. And most importantly, we built confidence as new owners of the code! The value of that became evident as we took on the day-to-day maintenance of the product as a team.

Tips and tricks for a successful ATTACK

For any team looking to implement their own ATTACK, here are a few pointers:

Stay up to date

Get the latest from Watershed, from policy updates to in-depth climate guides.

Loading form...
ATTACK: How To Grok New-To-You Code Via Testing – Watershed