- Lab
- Core Tech

Guided: Test Driven Development While Building a Set Class - Java 17
This hands-on lab is designed to help you practice test driven development while building a version of the Set data type in Java. A series of guided steps will walk you through the process of Test Driven Development which include writing a test, implementing functionality, and refactoring to maintain green to green test coverage. By the end of the lab, you will have demonstrated a strong understanding of the Test Driven Development process in Java.

Path Info
Table of Contents
-
Challenge
Implement Set Contains Following TDD
In this section, you will implement the
contains
method for aSet
class. This will require making minimal changes to theadd
method. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.
The files you will be working on throughout this lab is
src/test/java/com/pluralsight/SetTest.java
andsrc/main/java/com/pluralsight/Set.java
. The objective is to create a functioningSet
class that can be used like one would expect aSet
object would be. However, we will not be focused on performance like a traditional set.The solution file for a task that is implementing functionality can be found in
soln/step1/{corresponding task}/Set.java
.The solution file for a task that is implementing a test can be found in
soln/step5/SetTest.java
.It is important to note that if the task you are working on asks you to implement a test, you will be working in the
src/test/java/com/pluralsight/SetTest.java
file. Otherwise, you will be implementing functionality in thesrc/main/java/com/pluralsight/Set.java
file.To run tests, use the command
mvn test
. -
Challenge
Implement Set Add Following TDD
In this section, you will implement the
add
method for aSet
class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.
The solution file for a task that is implementing functionality can be found in
soln/step2/{corresponding task}/Set.java
.The solution file for a task that is implementing a test can be found in
soln/ste5/SetTest.java
.It is important to note that if the task you are working on asks you to implement a test, you will be working in the
src/test/java/com/pluralsight/SetTest.java
file. Otherwise, you will be implementing functionality in thesrc/main/java/com/pluralsight/Set.java
file. -
Challenge
Implement Set Remove Following TDD
In this section, you will implement the
remove
method for aSet
class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.
The solution file for a task that is implementing functionality can be found in
soln/step3/{corresponding task}/Set.java
.The solution file for a task that is implementing a test can be found in
soln/step5/SetTest.java
.It is important to note that if the task you are working on asks you to implement a test, you will be working in the
src/test/java/com/pluralsight/SetTest.java
file. Otherwise, you will be implementing functionality in thesrc/main/java/com/pluralsight/Set.java
file. -
Challenge
Implement Set Size Following TDD
In this section, you will implement the
size
method for aSet
class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.
The solution file for a task that is implementing functionality can be found in
soln/step4/{corresponding task}/Set.java
.The solution file for a task that is implementing a test can be found in
soln/step5/SetTest.java
.It is important to note that if the task you are working on asks you to implement a test, you will be working in the
src/test/java/com/pluralsight/SetTest.java
file. Otherwise, you will be implementing functionality in thesrc/main/java/com/pluralsight/Set.java
file. -
Challenge
Implement Set Clear Following TDD
In this section, you will implement the
clear
method for aSet
class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.
The solution file for a task that is implementing functionality can be found in
soln/step5/{corresponding task}/Set.java
.The solution file for a task that is implementing a test can be found in
soln/step5/SetTest.java
.It is important to note that if the task you are working on asks you to implement a test, you will be working in the
src/test/java/com/pluralsight/SetTest.java
file. Otherwise, you will be implementing functionality in thesrc/main/java/com/pluralsight/Set.java
file.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.