Minimalistic Design and Test Driven Development
Engineering a great design an evolutionary process. How can we evolve and refactor a design successfully through iterations?
This lecture takes a look at the Test Driven Development paradigm and how it can help!
In addition, this lecture sets up the initial problem and design solution. This design and resulting code, forms the basis for all labs used in this course.
The Company Class
Lab Time: 15-30 minutes
Objective: demonstrate the implementation of a class in a test-driven design.
For this lab, you will only complete class Company. A skeleton Employee class is provided since the type is referenced by company, but the evaluation code mocks the employees needed to test.
Download and unzip the file below.
Create a new NUnit .Net Core project in Visual Studio. Add the files from the zipfile to the project. Run the unit tests - they should all fail (3 tests).
- add private instance variables to hold id, name, and employees
- employees can be any collection you wish (List<Employee> for instance)
- In the company constructor, initialize name & id and create the employees collection
- should you use the properties or the fields?
- Complete the trivial properties. There is no requirement to validate in the setters at this time
- Complete the Hire methods. In the second Hire method, you will need to new an employee
- Complete the Pay method
- loop through the employees list, adding up the results of paying each employee; return the total
- Is there a LINQ method that can help?
Lab 2 - Employee Class
Lab TIme: 15 to 30 minutes
Objective: continuation of TDD example, creating a domain class used in subsequent labs
In this lab, you will complete the Employee class.
Download and unzip the zipfile below. Add Evaluate.cs to your project, overwriting the existing Evaluate.cs. This will add the unit tests for Employee, which should fail.
- Review Company.cs. This is a solution to the previous code exercise
- Create instance variables in Employee for id, name, salary, ytdSalary, ytdNet
- Implement the parameterized constructor to initialize the new employee (the default constructor is not used)
- Implement the properties
- Implement Pay()
- increment ytdSalary by Salary
- compute deductions - 12% tax, 4 to charity, 40 to parking
- increment ytdNet by salary - deductions
- return net (salary - deductions)
If you need a hint about the Employee class, peek here: