.NET Core 2.0 Testing Layers

Posted by

A few months ago I published an article detailing the layers of testing that a cloud application should have as part of a Continuous Delivery/Deployment pipeline. A friend and fellow developer recently mentioned that it’d be interesting to have a more detailed series on each layer with some samples to look at. And to make things even more interesting, I’m going to look at how to do so with .NET Core 2.0.

What We’ll Be Testing

This upcoming series of posts elaborates a plan on how to define, implement and operationalize each of the testing layers.

TestingLayersV2

The long-term goal is to have this project be the basis for testing a Continuous Deployment pipeline with .NET Core. The requirements to demonstrate the whole process are as follows:

  • Some business logic for unit testing.
  • An API with at least one endpoint for acceptance and contract testing.
  • Use of another API for External Contract Tests.
  • A simple form of authentication and authorization for security testing.
  • A UI for end to end testing.

You’ll notice I skipped the load and performance testing layer. That’s because I’ve covered that topic in depth already, and there isn’t much value to returning to it since this won’t be a real, full-fledged application against which we can test performance. With those needs in mind, it’s time to find a problem that can satisfy them.

A Theoretical Problem Needed

The biggest challenge was coming up with the problem space that would give me the flexibility I needed to demonstrate all the elements mentioned above. I also wanted the problem to do something that could potentially be real. Keep in mind that the problem is merely a vehicle to explore the testing layers and that the actual implementation details don’t matter all that much.

shopping-cart-1275480_640

I turned to a popular coding kata website to find an appropriate problem. Katas have a decent level of complexity to them and the Supermarket kata provides me with everything that is needed. The goal of this kata is to determining the price of a shopping cart, with different rebates applied on each type of item in the cart. It’s fairly simple at first glance but there are lots of subtleties once you get into it.

The kata as a whole is larger than what’s needed so it’s been trimmed down to only checking out a cart of items. For our purposes, we’ll assume the cart gets populated somehow without doing it ourselves.

Technology Choices

There were a few tech stack choices that needed to be made before I could start on the first layer. The first of those decisions was where to host the source code. The obvious answer was of course GitHub. I also investigated VSTS but the lack of public repositories was a non-starter for a project that I wanted to be available to anyone who is interested.

Then came the question of which version of .NET to use. Most developers are still working with .NET Framework in their day-to-day job and will be doing so for a long time still. But the number of projects being migrated to .NET Core is increasing and I found the option of exploring its ecosystem especially interesting.

I’m a Mac user who runs Windows in Parallels but prefers to stay in macOS as much as possible. That made the decision on which IDE to use especially interesting. Both Visual Studio and Code work on both platforms and are equipped to build .NET Core apps. Since .NET Core is open-source and embracing Linux environments, I figured it was a good time to give it a whir on macOS with Visual Studio Code.

Let’s Get Going

I discovered a few things while setting up the project. The first is that there’s no default .gitignore file on GitHub for C#. The .NET Foundation has a good one on their GitHub repository. Always create your .gitignore before writing any code whatsoever. It’ll save you lots of pain later with trying to remove the bin and obj folders. I found out the hard way!

The only other problem that I’ve run into so far is an issue with the Omnisharp extension showing valid statements as errors. Restarting the extension from the Command pallete (Cmd-Shift-P, Restart Omnisharp) has fixed it every time.

And finally, here’s the link to the GitHub repo for the project.

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s