Test-Driven Development

Pivotal/Tanzu Labs

Testing is crucial to cloud native application development. It is our primary (and sometimes only) way to build confidence that we can push to production at any given time.

Test Types

In many traditional organizations with independent, quality assurance and testing teams, software engineers may only leverage unit tests. As a balanced team with complete ownership of releases, we write and own an extensive spectrum of tests for our app. These include:

  • Unit Tests
  • Integration Tests
  • Contract Tests
  • Behavior Tests

While we may use some additional layers such as end-to-end tests or automated UI tests, these are the most expensive to run. We look to build confidence with the other leaner test layers when possible.

  • Read what Martin Fowler and his team have to say on the test pyramid, and how it provides a solid foundation for answering questions such as “at which layer should I test this functionality?”.

  • Read this article to learn more on testing various slices of your Spring Boot application.

  • Read through the Quick Start Guide on Consumer-Driven Contract testing with Spring Cloud Contract.

  • Read an introduction to behavior-driven development (BDD) and run through the basic tutorial on using Cucumber in a Java project.

The Basics of Test Driven Development

Now that you know the tools you have to test your application, it’s time to learn how to use those tools in your development project.

VMware Tanzu develops software using the test-driven development methodology of writing tests to describe our intended behavior. First, we write tests, see our tests fail, build the functionality to make our tests pass, and clean up any technical debt created during the process. This approach is often referred to as the “red-green-refactor” loop. The best way to learn about test-driven development is to do some of it! Pairing with an experienced software engineer will give you lots of practice. Or, if you prefer to do it yourself, you can prepare by reading this article on TDD exercises and running through some of the first requirements for the Greeting exercise in your IDE.

Homework

  • Read linked articles on the test pyramid and specific kinds of testing.
  • Run through at least three requirements from the Greeting exercise.

Additional resources