Book Image

C# and .NET Core Test Driven Development

By : Ayobami Adewole
Book Image

C# and .NET Core Test Driven Development

By: Ayobami Adewole

Overview of this book

This book guides developers to create robust, production-ready C# 7 and .NET Core applications through the practice of test-driven development process. In C# and .NET Core Test-Driven Development, you will learn the different stages of the TDD life cycle, basics of TDD, best practices, and anti-patterns. It will teach you how to create an ASP.NET Core MVC sample application, write testable code with SOLID principles and set up a dependency injection for your sample application. Next, you will learn the xUnit testing framework and learn how to use its attributes and assertions. You’ll see how to create data-driven unit tests and mock dependencies in your code. You will understand the difference between running and debugging your tests on .NET Core on LINUX versus Windows and Visual Studio. As you move forward, you will be able to create a healthy continuous integration process for your sample application using GitHub, TeamCity, Cake, and Microsoft VSTS. By the end of this book, you will have learned how to write clean and robust code through the effective practice of TDD, set up CI build steps to test and build applications as well as how to package application for deployment on NuGet.
Table of Contents (11 chapters)

What this book covers

Chapter 1, Exploring Test-Driven Development, introduces you to how you can improve your coding habits and code by learning and following the proven principles of test-driven development.

Chapter 2, Getting Started with .NET Core, introduces you to the super-cool new cross-platform capabilities of .NET Core and C# 7. You will learn by doing as we create an ASP.NET MVC application on Ubuntu Linux with test-driven development principles.

Chapter 3, Writing Testable Code, demonstrates that, in order to reap the benefits of a test-driven development cycle, you must write code that is testable. In this chapter, we will discuss the SOLID principles for creating testable code and learn how to set up our .NET core application for dependency injection.

Chapter 4, .NET Core Unit Testing, presents the unit testing frameworks available for .NET Core and C#. We will use the xUnit framework to create a shared test context of setup and teardown code. You will also understand how to create basic unit tests and prove the results of your unit tests with xUnit assertions.

Chapter 5, Data-Driven Unit Tests, presents concepts that allow you to test your code over a variety of inputs by running over a set of data, either inline or from a data source. In this chapter, we will create data-driven unit tests or theories in xUnit.

Chapter 6, Mocking Dependencies, explains that mock objects are simulated objects that mimic the behavior of real objects. In this chapter, you will learn how to use the Moq framework to isolate the class you're testing from its dependencies using mock objects created with Moq.

Chapter 7, Continuous Integration and Project Hosting, focuses on the goal of the test-driven development cycle of quickly providing feedback on code quality. A continuous integration process extends this feedback cycle to uncovering code integration issues. In this chapter, you will begin creating a continuous integration process that can provide rapid feedback on code quality and integration issues across a development team.

Chapter 8, Creating Continuous Integration Build Processes, explains that a great continuous integration process brings together many different steps into an easily repeatable process. In this chapter, you will configure TeamCity and VSTS to use a cross-platform build automation system called Cake to clean, build, restore package dependencies and test your solution.

Chapter 9, Testing and Packaging the Application, teaches you to modify the Cake build script to run your suite of xUnit tests. You will finish up the process by versioning and packaging an application for distribution on the various platforms that .NET Core supports.