CategoryRamblings

Unit, integration, end-to-end tests: do I need all of them?

Yes. I mean, don’t even think about it. You’ll need all of them, probably in different measures, but there is no “we shipped to production without tests”.

Tests are the first rampart separating you from madness and failure.
Why madness? Try to do even a small refactoring after you’ve deployed your app. Without automatic tests you’ll have to manually probe the entire system (or systems if you’re on microservices).

Why failure ? Simple, just think on the long run. Maintenance will quickly become a hell and adding new features will soon bring you to the infamous “it’s better if we re-build this from scratch”.

So! Where should we start? From the pyramid!

the test pyramid

The test pyramid. Image taken directly from Martin Fowler’s article. Thanks, Martin.

Starting from the bottom, you’ll begin with writing the unit tests. “Unit” here means that you’re testing a single small atomic piece of your system, a class, a function, whatever. You won’t connect to any external resource (eg. database, remote services) and you’ll be mocking all the dependencies. 
So, ideally you’ll be checking that under specific circumstances a method is throwing an exception or the cTor is populating the class properties or the result of a computation is a specific value giving a controlled input.
Also, unit tests have to be extremely fast, in the order of milliseconds, giving you a very quick and generic feedback of your system.

Next is the “Service” layer or, more commonly, “Integration”. This is where things start to get interesting. Integration tests check that two or more pieces fit correctly and the cogs are oiled and greased.  So stuff like your Persistence layer, access to the database, ability to create or update data and so on. They might take more time than  unit tests and probably will be in a lesser number, but their value is extremely high.

Then we have the “UI” or “end-to-end” tests. Here we’re making sure that the whole system is working, inspecting from the outside, with little to none knowledge of the inner mechanism. You’ll be checking that your API routes are returning the right HTTP statuses, setting the proper headers and eating the right content types.

In the end it’s all a matter of perception. The point of view is moving from the inside of the system, the developer perspective, to the outside: the consumer perspective.

There are of course other typologies of tests, acceptance, smoke, functional and so on. But if you begin adding the coverage using this pyramid you’ll save an awful lot of headaches and keep your system maintainable and expandable.

DevDay Salerno: let’s talk about Feature Gating!

Tomorrow I’ll be speaking at the monthly Meetup hosted by the DevDay Salerno community! The topic of the day will be “Feature Gating“, I’ll talk about the general idea, use cases and best practices. The talk will be language-agnostic as this is more a pattern rather than a framework/library. I will show some code but try to keep the discussion more on the “theory-side”. 

I have always been more attracted to software architecture and design patterns so I tend to avoid putting too much effort in whatever library is the hype of the moment. 

Feature Gating is an interesting and easy tool to leverage when you want more flexibility during production deployment. It helps controlling and shipping new features faster allowing practices like canary releases and A/B testing.

One of the event organizers is an old friend of mine and ex coworker from my Healthware days. A while ago we discussed about having me presenting something but, as often happens, life stood in the way (along with me moving to a different country altogether).
So as soon as I had the chance to plan ahead my trip back to Italy he managed to find a slot for me 🙂 

Unfortunately the slides are in Italian so I don’t think I’ll share them on this blog but I will be writing soon a more detailed post so stay tuned!

In the meantime, if you’re near Salerno and fancy a little geekiness come and say hi!

 

Free Microsoft eBook giveaway!

A friend of mine just pointed me to a very interesting link that I think it’s worth sharing: https://blogs.msdn.microsoft.com/mssmallbiz/2017/07/11/largest-free-microsoft-ebook-giveaway-im-giving-away-millions-of-free-microsoft-ebooks-again-including-windows-10-office-365-office-2016-power-bi-azure-windows-8-1-office-2013-sharepo/ 
It’s from the Eric Ligman blog on MSDN, he’s sharing a HUGE list of Microsoft eBooks about basically everything, from Azure to Office, to Powershell to .NET development.

I have started with Machine Learning on Azure since it is a huge hype these days and I definitely need to give it a try.

I have been reading also a lot about Microservices lately and I’m still waiting my good friend and colleague Lalit to sign me a copy of his book .

Another thing I am investigating is Xamarin. Personally I am not a huge fan of mobile applications, I believe “standard” web development will replace native apps (maybe not cpu/gpu intensive applications like games for example) but I also believe that is good to have at least a minimal knowledge of it. 

In any case, if you enjoy reading or you’re just curious, don’t miss it!

How I almost lost all my source codes.

Now sit down my dear and listen carefully, I’ll tell you a story about how I almost lost all my sources.
A while ago, I decided to give my marvelous Macbook pro mid-2013 an upgrade. I searched online a little bit and at the end I bought an SSD drive, a Corsair Force LE 240GB

“But 240 is not enough!” you might say.  “You’re right”. It’s not enough. 

I was not using the DVD drive at all so after a brief research, I found the right adapter and replaced it with the old 500gb Apple disk , leaving space for my shiny new SSD.

Everything was perfect, El Capitan was lightning fast, everybody was happy. But then came the day that I needed Windows. So Bootcamp joined us and new partitions started to appear.

180GB OSX Extended and 60GB NTFS on the SSD.
450GB OSX Extended and 50GB exFAT on the ol’ Apple disk.

Again, everything was perfect, El Capitan was still lightning fast, Windows 10 was running fine, everybody was happy.

I was running Windows from the SSD and all the programs were installed on the other drive, together with all the source codes. Yes, before you ask, I have a Bitbucket account. Yeah, a Github one too, but Bitbucket gives you private repos for free.

However, after a while, I realized that when Win10 goes to sleep mode some strange misbehavior appears, in the form of weird SMART messages when turning on MacOs.

Long story short, one day I rebooted from Win to MacOs and puff! the partition with all the sources was gone. Disappeared. An empty, dark and cold space.
I almost got an heart attack.

Disk Util, Disk Warrior, mysterious command line tools, I tried everything, nothing worked. After hours of researches and curses, I fired up Windows and did the only thing I had left:

chkdsk e: /f

That saved my day.

Moral of the story? Always backup your source codes, even the most insignificant snippets.

© 2018 Davide Guida

Theme by Anders NorenUp ↑