Code Monkey home page Code Monkey logo

exercises_06's Introduction

DNP Exercises 06 - Unit Testing and TDD

Exercise 1 - Unit testing in .NET

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.

Exercise 2 - Fact and Theory

Rewrite as many tests in HeroTest as possible using Theory and InlineData

Exercise 3 - Project Setup

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.

Exercise 4 - Dependency Injection

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).

Exercise 5 - Fakes, Stubs and Mocks

Test the Combat class from previous exercise, creating stubs for FlipCoin() and RollDice(). Improve the class where your tests expose bugs or weaknesses.

reference

Exercise 6 - Test Driven Development

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:

  1. Write a test
  2. Run all tests and see the new one fail
  3. Write the simplest code to pass the test
  4. Run all tests and see them succeed
  5. Refactor
  6. Repeat from step 1

exercises_06's People

Contributors

sandbeck avatar metamate avatar

Watchers

Taha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.