Unit Testing I Lab
Lab Objectives
- Practice creating tests for class Properties and Methods.
- Introduce Code Refactoring.
Practice
To reinforce our testing lesson, you are going to implement tests for the Library System that we worked on earlier. Now that we are using the Visual Studio IDE, we will want to re-create this project as a Visual Studio solution.
- Create a new Visual Studio Console Application - let’s call it
DenverPublicLibrary
- Create classes for Book, Branch, and Library:
Keep an eye on Slack - we will be re-grouping frequently to discuss our progress
Create a Test Project and First Tests
In small groups, spend 20 minutes to create an xUnit test project, called DenverLibrary.UnitTests
.
Write tests for the methods and properties of the Book
class. You should end up with at least 1 test.
Be prepared to share your test(s).
Create Tests for the Branch Class
Back in your small groups, spend 20 minutes writing tests for the Branch
class. Keep in mind that each class should have its own test file!
When finished, you should have a minimum of 3 new tests.
Be prepared to share your tests, and how you determined what should be tested.
Create Tests for the Library Class
Individually, spend 20 minutes writing tests for the Library
class. When finished you should have a minimum of 4 new tests.
Be prepared to share one or more of your tests, and how you decided what tests to write.
Preparation
As an introduction to our Refactoring lesson next week, take a few minutes to read this blog post on Refactoring. This is meant to be an introduction, don’t worry if not everything in the post makes total sense - there are some references to other code practices that we haven’t touched on yet, but you will still get a good intro to Refactoring.
After reading the post, in your journal reflect on the following questions:
- What is refactoring?
- Why is refactoring necessary?