Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Practical Test-Driven Development using C# 7
Practical Test-Driven Development using C# 7

Practical Test-Driven Development using C# 7: Unleash the power of TDD by implementing real world examples under .NET environment and JavaScript

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Practical Test-Driven Development using C# 7

Setting Up the .NET Test Environment

In this chapter, we'll explore setting up your development environment. We'll be covering both C# and .NET. In the following chapter, we will focus on setting up a JavaScript and React environment. We'll delve into more examples, starting with the classic code kata entitled FizzBuzz, and then into more real-world samples from the Speaker Meet site.

In this chapter, you will gain an understanding of:

  • Installing your IDE
  • How to set up your testing framework
  • Writing your first tests in C#

Installing the .NET Core SDK

Before you get started with the development environments, you will want to install the .NET Core SDK. You'll need to navigate to the .NET Core download page on the Microsoft website (https://www.microsoft.com/net/download/core). Select the proper installer for your system. For Windows machines, the .exe download is recommended.

Follow the onscreen instructions for the install wizard to install the .NET Core SDK.

Getting set up with VS Code

One benefit of choosing VS Code for your development is that it is an excellent IDE for both .NET and JavaScript. To get started using VS Code, you must first download the IDE. 

...

Creating a project in VS Code

Now that your VS Code IDE is properly installed with the C# extension enabled, you are ready to create your first project.

With VS Code open, choose Open Folder from the File menu. Choose a location that is easily accessible. Many developers will create a Development folder on the root of their drive. Whatever convention you're used to will be fine. You now need to create an MSTest project.

Create a new folder named Sample. Open the Integrated Terminal window from the View menu or by using the shortcut keys (Ctrl + `). From within the Terminal window, type dotnet new mstest and hit Enter. Now, you need to restore your packages by typing dotnet restore into the Terminal window and hitting Enter.

You should now see a file named UnitTest1.cs within the Sample folder. If you open the file, it should look something like this:

using Microsoft...

Switching to xUnit

MSTest has long shipped with Visual Studio. There are a few other options when it comes to testing frameworks for C# and .NET. Many of these frameworks have feature parity and differ only slightly in their choices of attributes, assertions, and exception handling. Among the top contenders for testing frameworks is xUnit. Many developers actually prefer this to MSTest and would argue that it is more feature-rich and has stronger community support. Arguments aside, we'll be using xUnit for our C# and .NET tests from here on out.

Feel free to stick with MSTest if you prefer. Just know that you'll need to account for the semantic differences (such as TestMethod vs Fact) and slight differences in functionality.

Code katas

...

What is Speaker Meet?

We're using the Speaker Meet application as a case study in Test-Driven Development. Speaker Meet is a website dedicated to connecting technology speakers, user groups, and conferences. Anyone who has helped organize a user group or tech conference knows it’s often difficult to find speakers. And as technology speakers, it's often difficult to coordinate speaking engagements outside your immediate area. Speaker Meet helps bring technology speakers and communities together.

At the time of writing, the application is still in development, but it is a terrific platform to explore TDD concepts and principles as they relate to real-world applications. Speaker Meet consists of a RESTful API in .NET with a Single Page Application (SPA) in JavaScript, utilizing the React library.

...

Summary

You should now feel quite comfortable with your .NET development environment. The .NET Core SDK should now be installed and your IDE configured. You've had some exposure to unit tests and continuous test runners in Visual Studio and VS Code. 

In Chapter 3, Setting Up the JavaScript Environment, we'll focus on getting our JavaScript environment set up.

Left arrow icon Right arrow icon

Key benefits

  • • Develop a thorough understanding of TDD and how it can help you develop simpler applications with no defects using C# and JavaScript
  • • Adapt to the mindset of writing tests before code by incorporating business goals, code manageability, and other factors
  • • Make all your software units and modules pass tests by analyzing failed tests and refactoring code as and when required

Description

Test-Driven Development (TDD) is a methodology that helps you to write as little as code as possible to satisfy software requirements, and ensures that what you've written does what it's supposed to do. If you're looking for a practical resource on Test-Driven Development this is the book for you. You've found a practical end-to-end guide that will help you implement Test-Driven Techniques for your software development projects. You will learn from industry standard patterns and practices, and shift from a conventional approach to a modern and efficient software testing approach in C# and JavaScript. This book starts with the basics of TDD and the components of a simple unit test. Then we look at setting up the testing framework so that you can easily run your tests in your development environment. You will then see the importance of defining and testing boundaries, abstracting away third-party code (including the .NET Framework), and working with different types of test double such as spies, mocks, and fakes. Moving on, you will learn how to think like a TDD developer when it comes to application development. Next, you'll focus on writing tests for new/changing requirements and covering newly discovered bugs, along with how to test JavaScript applications and perform integration testing. You’ll also learn how to identify code that is inherently un-testable, and identify some of the major problems with legacy applications that weren’t written with testability in mind. By the end of the book, you’ll have all the TDD skills you'll need and you’ll be able to re-enter the world as a TDD expert!

Who is this book for?

This book is for software developers with a basic knowledge of Test Driven Development (TDD) who want a thorough understanding of how TDD can benefit them and the applications they produce. The examples in this book are in C#, and you will need a basic understanding of C# to work through these examples.

What you will learn

  • • The core concepts of TDD
  • • Testing in action with a real-world case study in C# and JavaScript using React
  • • Writing proper Unit Tests and testable code for your application
  • • Using different types of test double such as stubs, spies, and mocks
  • • Growing an application guided by tests
  • • Exploring new developments on a green-field application
  • • Mitigating the problems associated with writing tests for legacy applications
  • • Modifying a legacy application to make it testable

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 15, 2018
Length: 442 pages
Edition : 1st
Language : English
ISBN-13 : 9781788390606
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Feb 15, 2018
Length: 442 pages
Edition : 1st
Language : English
ISBN-13 : 9781788390606
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 134.97
Practical Test-Driven Development using C# 7
€41.99
Learn C# in 7 days
€32.99
C# 7.1 and .NET Core 2.0 ??? Modern Cross-Platform Development
€59.99
Total 134.97 Stars icon

Table of Contents

15 Chapters
Why TDD is Important Chevron down icon Chevron up icon
Setting Up the .NET Test Environment Chevron down icon Chevron up icon
Setting Up a JavaScript Environment Chevron down icon Chevron up icon
What to Know Before Getting Started Chevron down icon Chevron up icon
Tabula Rasa – Approaching an Application with TDD in Mind Chevron down icon Chevron up icon
Approaching the Problem Chevron down icon Chevron up icon
Test-Driving C# Applications Chevron down icon Chevron up icon
Abstract Away Problems Chevron down icon Chevron up icon
Testing JavaScript Applications Chevron down icon Chevron up icon
Exploring Integrations Chevron down icon Chevron up icon
Changes in Requirements Chevron down icon Chevron up icon
The Legacy Problem Chevron down icon Chevron up icon
Unraveling a Mess Chevron down icon Chevron up icon
A Better Foot Forward Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(11 Ratings)
5 star 63.6%
4 star 0%
3 star 9.1%
2 star 27.3%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Pedro Quintero Mar 27, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an excellent book, both as a reference and as an introduction to test-driven development. This book is for intermediate level programmers, it's full of best-practices and is easy to follow, with practical examples and clear narrative. I wish there was a companion site for the code used in the book. I found useful techniques (besides TDD) here that I am using in my projects. Highly recommended.
Amazon Verified review Amazon
Amazon Customer Jul 05, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have been struggling for some time as a solo developer to produce quality code on time within the expectation of the stakeholder. I never have enough time to debug and test. I had heard of TDD before this book but thought of it as something to abstract for my to tackle in the heat of the battle. However, last weekend I opened this book that I heard about on the Completed Developer Podcast. I consumed it in about 18 hours. By the end of the book, something that seemed far away was within reach. I had a section of code that I needed to refractor bad. So, using TDD I started developing a microservice to replace the back-end portion. It was slow at first, but once I got into a stride with Moq and XUnit, and with the examples from the book, I was off to the races. I will not say I have implemented TDD perfectly in this case or have great code coverage etc… But I feel a lot more comfortable and confident launching this feature update in a week than I have in any past launches over the last two years. I just know the code works.From a professionalism stand point I feel like I just made a huge leap forward in my code writing it just seems better and makes so much sense. The huge part to the story is that I am a contract consultant. With my current customer I was probably one failed demo away from have a cancelation notice issued. I know now for a fact that the demo will go as planned. There will not be any “oh crap I forgot to fix that”, while showing the features to the customer. The launch will go better, everyone is happy. Thank you both for writing this book in a very understanding and meaningful way. The examples and download code are spot and super easy to walk through.
Amazon Verified review Amazon
Crystal Tenn Mar 01, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a great read, is feels very practical and easy to understand. I like how the intro breaks down TDD and related terminology into layman terms then digs deeper with samples, tips, and best practices for a realistic enterprise view. There is certainly developer humor in the writing, and it is easy to relate to the authors and many of the feelings good and bad I have had about enterprise code are echoed in the text. I love how the book has broken up different ideas into small digestible sections that make good chronological and logical order. Many texts are chock full of words without much direction, and they found a way to make a practical order so learning is easier.The book covers specific examples using C#, JavaScript (and React), and helps you setup sample code with clear instructions. Also, they talk about un-testable code, which is equally important to be able to recognize. If you know what can't be tested, you know how to write better code that can maximize the amount of tested code which was great to read about! I was also happy to see mocking, design patterns, dependency injection, and APIs covered in the text in addition as it relates to TDD.Overall, I think if you want to learn TDD and have little or a lot of experience, you can still learn a lot from this book. I highly recommended reading it and wish I had a copy of it when I first started development!
Amazon Verified review Amazon
Ward Mar 15, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Clean, simple, and easy to understand approach to TDD.The authors hit one out of the ballpark with this one. The authors not only know TDD but also understand the problems developers, like myself, face involving TDD. Some of these problems are understanding the concepts, setting up an environment, or even digging into old code. They have covered the material from the viewpoint of standing up a new application all the way to, the dreaded, legacy code - that stuff we seem to get handed and have no idea how to handle. Now we have a strategy!What I like most about this book is the journey the reader is taken on. No assumptions are made, every topic has clear explanations, examples, and when applicable, code samples. What's more, the discussions focus on both C# and JavaScript - two of the largest used languages for both frontend and backend development.In prior years, I've struggled with knowing how to implement TDD into my development team. The one piece I was missing, which this book highlights perfectly, is the mindset on testing first. Thinking about tests first, instead of writing code results in better code. By better code, of course, I mean fewer bugs and increasingly faster development time.
Amazon Verified review Amazon
Jay V May 16, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Overall, this is a great introduction to Test Driven Development in .NET, and in general. In the process, it's also a pretty good introduction to building an ASP.NET Core application from scratch.I really appreciated how the authors were able to provide examples of many of the actual problems I've seen when trying to apply TDD principles, and then provide practical solutions (sometimes more than one). I also liked seeing the different approaches to TDD in various application layers, e.g. using Mocha and Chai in a React front-end. I'm not sure I'd 100% agree with their choices of test frameworks, but the examples provided were easy enough to follow along and apply in any environment.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.