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

Arrow left icon
Profile Icon Callaway Profile Icon Hunt
Arrow right icon
Can$69.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (11 Ratings)
Paperback Feb 2018 442 pages 1st Edition
eBook
Can$38.99 Can$55.99
Paperback
Can$69.99
Subscription
Free Trial
Arrow left icon
Profile Icon Callaway Profile Icon Hunt
Arrow right icon
Can$69.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (11 Ratings)
Paperback Feb 2018 442 pages 1st Edition
eBook
Can$38.99 Can$55.99
Paperback
Can$69.99
Subscription
Free Trial
eBook
Can$38.99 Can$55.99
Paperback
Can$69.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Canada

Economy delivery 10 - 13 business days

Can$24.95

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 : 9781788398787
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Canada

Economy delivery 10 - 13 business days

Can$24.95

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 Can$6 each
Feature tick icon Exclusive print discounts
$279.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 Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 227.97
Practical Test-Driven Development using C# 7
Can$69.99
Learn C# in 7 days
Can$55.99
C# 7.1 and .NET Core 2.0 ??? Modern Cross-Platform Development
Can$101.99
Total Can$ 227.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

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela