Sunday, July 12, 2020

Building an Alexa Skill for Daily Covid-19 Stats Using Serverless

In my house, we always want to know how many new Covid-19 cases were recorded in our county over the last day. Obviously there are lots of places on the Internet where you can find this out. However, I'd rather just ask a digital assistant. So I built an Alexa skill and a system in AWS to back it up using serverless technology (Lambda and DynamoDB). Here I'll make a few notes on how I did it.

Here's the architecture:

I started by looking around for different data sources broken down by U.S. state and county that are being maintained around the web and settled on one being stored in a Github repo. So the first Lambda, update-stats, grabs the data once a day and processes it into DynamoDB.

One drawback to this particular data source is that it gives cumulative rather than daily counts. To derive the daily counts, I store the data over time. How to do this in DynamoDB and not preclude possible future extensions (like rollups over different dimensions) was the toughest decision I had to make on this project. Ultimately, I settled on a widening the table row (keyed by state:county) each day. Fingers crossed, but the virus should be long gone before I start to hit any row limits.

The second Lambda serves the Alexa skill. It simply loads the required row from DynamoDB and evaluates the two most recently added columns to calculate the daily change in positive cases.

The Lambdas are written in NodeJS, the AWS SDK, and alexa-message-builder and deployed and managed with Claudia.js. I wrote a few unit tests that I execute with Mocha; however, with Claudia, it's just as easy during development to upload and test most stuff inside the AWS console and CloudWatch logs.

I haven't made the skill public yet and am not sure if I will. Before that happens, there's a fair amount of productionization work left to do. Nonetheless, this was an interesting single-day project. Feel free to reach out if you have any questions.

Sunday, May 24, 2020

Moving to JUnit 5

JUnit 5 has been available for several years now. Yet I've seen and heard from many organizations that stubbornly stick with JUnit 4. Yes, it meets their needs, but if they were to make the leap to JUnit 5, they would benefit from all the great new features. And it's not that hard to move forward.

I've attempted to provide a bit of encouragement in the form of a new e-book, "Moving to JUnit 5: Migrating and Using the New Features". It's a breezy guide in two parts:
  1. Moving from earlier versions of JUnit to JUnit 5.
  2. Learning the new JUnit 5 features.
The complete book description is below. I hope you will check it out!

Looking to migrate from JUnit 4 to JUnit 5? Need a quick introduction to new JUnit 5 features?

JUnit 5 brings exciting features and unlocks new styles for writing unit test code in Java. But many projects are still using earlier versions of JUnit and struggling with the decision to move forward. This book will help you make your move to JUnit 5 in two steps:

•Migrating from older versions of JUnit.
•Taking full advantage of JUnit 5.

In the first half of the book, we discuss gradual migration, new annotations, changes to commonly used assertions, and replacing runners and rules with extensions. In the second half, we cover new JUnit 5 features like grouping of assertions, nesting test cases, writing conditional test cases, injecting parameters, and more.

At the end of the book, you will know everything you need to know to confidently move to JUnit 5 and write more modern and fun unit tests.

Saturday, April 25, 2020

New Book Alert: Microservices Testing in Brief: Using Hoverfly, Pact, and Containers

Recently, I published another book in the Kindle Store, and I wanted to draw your attention to it because if you're doing microservices, I think it can really help you out.

It's called "Microservices Testing in Brief: Using Hoverfly, Pact, and Containers". The material is based on some well-received training I taught in Beijing about a year ago. Here is the description:

Modern software systems are increasingly built using a microservices architecture, where functionality is broken down into many small servers that connect over remote procedure calls. Microservices bring lots of benefits in terms of scalability and development team agility.

But microservices can also complicate the testing process. Fortunately, new tools and approaches are available to tackle these challenges.

In this hands-on book, we will get a brief introduction to:

•Unit testing using API simulation and Hoverfly.
•Integration testing with consumer-driven contracts and Pact.
•System testing with a test container in Docker.

At the end of the book, readers will have a solid foundation for introducing these testing techniques in their microservices environments.

Check it out and let me know what you think!

Saturday, April 11, 2020

Published "Mock Object Testing with Examples Using Mockito"

I just published my latest e-book, "Mock Object Testing with Examples Using Mockito" in the Kindle Store.

The focus of the book is on testing with mock objects in general, rather than a detailed guide to any specific framework. But I had some requests to rework my previous book, "Mock Object Testing with Examples Using EasyMock", to use Mockito. So here you go!


Mock objects are a powerful tool for unit testing in complex modern software systems. But mock object testing is also misunderstood by many developers who struggle to use mocks to create elegant, maintainable tests.

Using the popular Mockito framework for Java, this book reveals mock object testing across the entire expect-use-verify cycle. Topics include:
•Dependencies and Testable Design
•Creating a Mock from Scratch
•Nice and Strict Mocks
•Setting Expectations
•Mock Method Results
•Partial and Class Mocking

At the end of the book, readers will have a solid grasp on everything that can be done with mocks and be well-prepared to introduce mock object testing into their own unit tests.

Check it out, leave a review, and let me know what you think!

My new weekend project is a short guide to microservices testing based on some training I gave last year. Stay tuned for more news on that.

Sunday, March 29, 2020

HAR Sanitizer in DockerHub

HAR (HTTP Archive) files are a really useful troubleshooting tool for browser developers: You can take a HAR file from an end-user or tester, load it up in the Chrome debugger, and see the request and response data in the Network panel as though you replayed the scenario yourself. This is particularly helpful in debugging, 403's, 404's, and performance issues (among others).

There's a catch, though: HAR files contain sensitive information like auth headers, cookies, and other personal data. As a web developer, users should not be sending these to you, and you should not be attaching them to (say) JIRA issues.

To help with this problem, Google released an unofficial open source application called HAR Sanitizer. It allows you to upload a HAR file from which it will automatically strip well-known sensitive information (think: certain auth cookies) as well as any other fields you choose. The resulting "sanitized" HAR file is then theoretically safe to share with developers.

If you'd like to try it out, there's a live version running on AppSpot.

That said, I'm always a little bit nervous asking my users to upload sensitive information to a third-party website, even if it does appear to be one unofficially supported by Google. What if I could get them to run HAR Sanitizer on their local machines instead?

If you happend to look at the HAR Sanitizer installation instructions on Github, you might have noticed they are a little complicated. Probably not something I could explain to most users how to do.

But I DO think I can explain to most users (at least in-house users) how to run a Docker image. That's why I packaged up HAR Sanitizer and uploaded it to Docker Hub.

The image build code is here.

The image itself is here.

Let me know if you find this useful.