In this exercise you are provided a project in ./exercise_01/ to start out with. Take a look at the classes in GameModel
and implement the empty tests in GameModel.Tests
. Try to figure out what you should test from the names of the test methods.
Follow the principles from Unit Testing Best Pracices.
Rewrite as many tests in HeroTest
as possible using Theory
and InlineData
Create a new solution with a classlib
project and a xunit
project. Extract the code that are counting words and finding the longest word of a string from Exercise 1 in week 4, and create unit tests for them (recall the Zero One Many Boundaries Interfaces Exceptions Simple principles from SWE).
Use Unit testing C# in .NET Core using dotnet test and xUnit as a reference for setting up the solution, and the ASP.Net Engineering Guidelines for naming guidelines.
The Combat
class simulates different combats between two Heroes (provided with the starter code in the exercise_4 folder). The class uses a random number generator making it hard to test. Refactor the class so that the methods FlipCoin()
and RollDice()
are moved to an other class. This class should implement an interface declaring these two methods. Finally provide the class to the Combat
class when instantiated (dependency injection).
Test the Combat
class from previous exercise, creating stubs for FlipCoin()
and RollDice()
. Improve the class where your tests expose bugs or weaknesses.
Using TDD, write a program that generates a string of integers, starting at 1 and going up to 100 (separated by commas). Substitute any integer which is divisible by 3 with "Fizz", and any integer which is divisible by 5 with "Buzz", and any integer divisible by 3 and 5 with "FizzBuzz".
For example, the first 20 values would be:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Remember, all implementation logic should be driven by tests, using the below workflow:
- Write a test
- Run all tests and see the new one fail
- Write the simplest code to pass the test
- Run all tests and see them succeed
- Refactor
- Repeat from step 1