CI / CD Pipeline – Part 4

This time I thought I might add to what we’ve already done by including a unit test project in our Visual Studio solution, then changing our APPVEYOR build so that it runs our test fixture(s) as part of the build process. Finally, I thought I might also gather some code coverage statistics and publish those to a website called coveralls.io, so that anyone thinking of using our NUGET package can verify that the code has been tested as part of the delivery process.

Let’s start by adding the unit test project. Open our solution in Visual Studio, then hit the Ctrl+Shift+N key combination, which should display the following dialog:

addproject

When the dialog appears, choose the “Test” category, then choose the “Unit Test Project (.NET Framework)” option. Then, name your project accordingly – I chose to name my project CG.Walkthrough.Tests. Also, make sure the “Solution” drop down has the “Add to solution” option selected, since we want the new project to be part of our existing solution. Finally, press the “OK” button.

Now you should see a solution tree, in Visual Studio, that looks something like this:

solutiontree

From this point, we’ll need to add a reference to our CG.Walkthrough.Tests project, pointing to our CG.Walkthrough project. To do that, right click on the CG.Walkthrough.Tests project, where it says “References”, then choose the “Add Reference” menu choice.

addreferencemenu

That should popup the following dialog:

refmgr

Make sure out CG.Walkthrough project is checked, as a project reference, then hit the “OK” button.

Now we can write a little code so that we have something to test and something to test with. Let’s start with the CG.Walkthrough project, in the Class1.cs file. Edit the Class1 class so that it looks like this:

 

We’re not trying to produce great code here, just something that can be tested. Now, go to the CG.Walkthrough.Tests project, in the UnitTest1.cs file, and edit the UnitTest1 class so that it looks like the following:

 

Build everything, just to make sure there are no typos.

Great! now we have a unit test fixture for our project. We can check in all our changes to GITHUB and our CI / CD pipeline will pickup the changes and rebuild our project. Go look at the build output, in the APPVEYOR website, and you’ll notice that APPVEYOR saw our test fixture and ran the test as part of the build process:

buildoutput1

Terrific! We’ve added a unit test project to our solution and added it to our GITHUB project so that our APPVEYOR build server will build the tests and run them as part of each build. Getting to this point only took a bit of additional work and the payoff is that we now have a tool that takes care of our build with a single button push (pushing a change to GITHUB). Our build is repeatable as well and that’s a big thing so that we’ll always know exactly how we produced any given version of our NUGET package(s).

For most open-source NUGET packages the CI / CD pipeline we have now is probably good enough. Next time though, I’ll look at what it takes to add code coverage to our pipeline as well.

See ya then!