The course is part of this learning path
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 firstname.lastname@example.org.
- 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
- Software developers interested in using TDD to build .NET Core applications using C#
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).
Welcome back. In this last demonstration, I'm going to introduce you to the concept of code coverage and using an online service called Coveralls which is available for free to perform visualizations of code coverage reports.
Coveralls is an excellent service and it gives you great insights as to whether your unit is a covering in exercising your implementation and perhaps point to areas where you could have better unit testing.
Now, this concept will become clearer as we proceed the other thing about this demonstration is that we're going to update our existing get hub action to do this automatically for us. So, let's begin I'll jump back into the editor and I'll open our existing GitHub action.
Now beneath the test step, I'll add in a couple of new ones the first one will actually generate the code coverage data points or the data that makes up the report that will feed into the coveralls online servers. The second action is we actually publish the code coverage data and the coveralls.
So with both of those in place, I'll save now, the other thing we need to do is within our Bitcoin converter dot test project file. We need to update this and we need to add in another reference. So the exact update that we need to put in is found here so on branch nine, we scroll down we grab this snippet here and I'll paste it like so.
Save that, okay everything is in place now on the cover rules side of things, you need to have an account and then that account needs to be linked to your GitHub account. So here we can see that I've already done that linking okay, so that's all that's required.
Okay, so we'll go back to the editor and we'll now push our code into the repository. Now fingers crossed hopefully this will trigger our get hub action which in turn will then generate our code coverage data and publish it up into coveralls.
So we'll jump back into our GitHub repository or do a refresh. We can see that an action is underway, we'll navigate into it, we'll draw into build and we'll watch it complete. In particular, we're interested in these two new items generate test coverage report and publish test coverage report.
So the code coverage report data is now being generated that's done and we've now pushed it up into coveralls. Okay, that looks really good our build is completed and it's time to now navigate into coveralls and excellent. Here we can see our repo has shown up so this is the demo-c# test-driven development repo that we've been working on and we can see here that it's got 90% code coverage which is not bad if we drill into it and we scroll down to source files we can actually drill down here and actually see the areas within the source code within the implementation that have been exercised through our unit test.
So anything that's highlighted in green represents code that has been touched when our unit test is actually red. Anything that is in red shows where unit tests have not touched our actual implementation in this can be feedback into the test driven development cycle and help you to improve your unit tests as to areas where you need improved unit tests or additional unit tests.
Ultimately, we're trying to strive to keep this number as high as possible. Okay, so that's code coverage using coveralls now the final thing that I wanna show in this demonstration is the concept of badging on your read me. So you see here, we've got this badge and it's available so if we click on the embed we can grab the generated markdown, we'll copy it.
We'll jump back into our editor and on our read me file you can add that badge like so. Now since we're adding badges let's also do the same for our GitHub action. So we'll click on actions again, we'll click on the first one, we'll click on the ellipses here and we'll click on create status badge again we'll copy the generated markdown and bake within our editor we'll paste it and like so we'll save it and then we'll push this up into our repository.
Okay, that looks good we'll go back to the repository and this time, if we go to the project route we can see our read me has been updated and that we've got two badges one indicating our code coverage of 90% and the other one indicating that our GitHub action is passing so the builder's passing.
Okay, that now completes the demonstration I hope you've enjoyed these set of demonstrations in which I've shown you how to do test driven development using C#in various tools. Go ahead and close this lesson and we'll wrap up the course in the next 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, GCP, Azure), Security, Kubernetes, and Machine Learning.
Jeremy holds professional certifications for AWS, GCP, and Kubernetes (CKA, CKAD, CKS).