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 a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788398787
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

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
€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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.