Test-Driven Development (TDD) is a discipline that helps to create error-free, quality code, and drives productivity by reducing and eliminating errors as well as providing many other benefits.
This entry-level training course is designed to bring you quickly up to speed with the basic features and processes involved in performing C# based test-driven development using xUnit. It covers the key principles and practices of test-driven development, which you can then utilize within your own software engineering projects.
In this course, you'll be guided through an end-to-end sample project in which we use test-driven development to build, test, and package a .NET Core 3.1 C# based library that will provide an API to convert Bitcoins into foreign currency.
If you have any feedback relating to this course, please contact us at support@cloudacademy.com.
Learning Objectives
- Understand the fundamentals of TDD and xUnit
- Use TDD to build, test, and package a .NET Core 3.1 C# based library
- Perform TDD by performing Red-Green-Refactor iterations
- Learn how to use TDD to build, test, and package a .NET Core 3.1 C# based library
- Learn how to create unit tests using the xUnit testing framework
Intended Audience
- Software developers interested in using TDD to build .NET Core applications using C#
Prerequisites
To get the most out of this course, you should have a basic understanding of .NET Core and the C# programming language, as well as software development and the software development life cycle (SDLC).
Resources
Okay, welcome back. In this demonstration, I'm going to now build a .Net client console based project which imports our Bitcoin converter library which the GitHub action produced for us in the previous demonstration. And this will allow us to test and validate the overall functionality of the particular library.
Now, everything that I'm about to demonstrate is contained in the step eight branch. So the first thing we'll wanna do is create a new .Net console client-based project. So I'll copy this. I'll jump back into our environment and I'll paste there. So this is generating a new .Net core console based project.
Next, I'll simply copy the code as contained here and I will update the program dot CS file. Now, if I jump into our new directory and if I attempt to perform a .Net build, this will fail because we haven't yet imported the library. So what I'm going to do next is I'm going to go back to GitHub and I'm going to download this DLL that was produced for us by the GitHub action.
I'm now going to jump onto my terminal on my local host. And this time I need to copy from downloads their particular DLL and I'm going to place it in the Bitcoin converter, Bitcoin converter client, libraries directory, but I need to create a directory. So, under my client and I'm going to create a new folder called libraries, like so.
So back with my terminal that photo should now exist, which it does. And now we can see the presence of our Bitcoin converter dot co dot DLL that the GitHub action built, tested and released for us. Okay. The final thing to do to get compilation to succeed is to update the C# project file.
So rather than doing this by hand I'll jump back into our repo and simply copy all of this out and override it like so. Now, the key point here is that we're importing this DLL which we've stored here and that we're using runtime identifiers for the executable output. The first of which has format costs and the second of which is for Ubuntu which is the flavor .Net is running on. And we can confirm this if we go to our terminal and run .Net dash dash file. Here we can see the RID, is this guy here. So we need to produce the executable for this RID or Runtime Identifier.
Jumping back into our step eight instructions to actually perform the build, we want to run this command here. I'll copy that, I'll go back here. Now, to do this last piece of compilation, I need to actually copy recursively the Bitcoin converter dot client directory and store it on the Vagrant home directory, like so.
So the reason that I need to do this is that there's a problem with compiling where I'm kind of running in this hybrid false system setup where I'm running within Vagrant, but Vagrant this folder here, is actually mapped back to my host directory on this running on MacOs. I'm not sure what the problem is, but the way to get around it is to move the Bitcoin converter dot client onto the file system within Ubuntu that has nothing to do with my local host, which I've just done.
So I'll now jump into that directory and we're now ready to perform the compilation. So I'll pace the compilation command that will produce us an executable that will run on Ubuntu. Excellent. So the copulation has succeeded and it's produced us an executable fit-for-purpose for Ubuntu.
So, all we need to do now is actually run it. To do so, we simply navigate to the executable, like so. So there we go. Our executable is up and running and it's using the release that was was created by the GitHub action.
So, let's test it out. Let's say we wanna convert six and a half Bitcoins to USD, and there we go, we get the result. So in the background, my call has been made to the CoinDesk API to get the real time exchange rates. Let's try another one. Let's do 1000 Bitcoin into Euro. Okay. That now completes this demonstration. Go ahead and close it and I'll see you shortly on the last one.
Jeremy is a Content Lead Architect and DevOps SME here at Cloud Academy where he specializes in developing DevOps technical training documentation.
He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 25+ years. In recent times, Jeremy has been focused on DevOps, Cloud (AWS, Azure, GCP), Security, Kubernetes, and Machine Learning.
Jeremy holds professional certifications for AWS, Azure, GCP, Terraform, Kubernetes (CKA, CKAD, CKS).