Posts

Showing posts with the label Unit Testing

GNU Autotools II - "Hello world" project with tests

Spanish version / Versión en Español In order to explore the concepts from the first post in a more practical fashion, today we will look at a step by step guide for creating a C programming language project built and tested using Autotools . 1: Application entry point This will be src/main.c . It's typical to have a src directory for source code, because when the project grows, it will probably need other top-level directories such as man for man pages , data for data files, and so on. src/main.c #include <config.h> #include <stdio.h> int main (void) { puts("Hello World!"); puts("This is " PACKAGE_STRING "."); return 0; } Including config.h is necessary because that's where PACKAGE_STRING will be defined. In turn, config.h will be generated by Autotools. 2: Top-level configure.ac file All configure.ac files contain Autoconf instructions which control the generation of the configure script. These...

C++: Adding unit tests to Arduino code

Spanish version / Versión en Español One of the advantages of pure unit testing is validating logic in isolation from external dependencies. In the case of Arduino, it's possible to test an entire sketch without a physical board and (almost) without modifying the original code. In his book "Working effectively with legacy code" , Michael Feathers introduces the concept of seams . He defines them as places in the source code where it's possible to swap out an external dependency for a fake object in order to isolate the calling code for testing purposes. In today's post, we'll walk through a concrete example of some techniques that exploit these seams. In particular, we will do this for a simple Arduino project. As a starting point, let us consider the following Wokwi project . For the sake of context, Wokwi is a website that allows users to create Arduino projects using just a web browser, without a physical board or even installing any software. Wo...

C++: Agregando tests unitarios a código Arduino

Versión en inglés / English version Una gran ventaja de tener tests unitarios puros es poder validar la lógica del código de manera aislada de las dependencias externas. En el caso de Arduino, es posible probar el sketch completo sin una placa física, y además, sin modificar el código original. En el libro "Working effectively with legacy code" , Michael Feathers habla del concepto de seam (costura). Para Feathers, un seam es un punto del código donde se puede reemplazar una dependencia externa con un objeto falso a fin de poder ejecutar el código en un ambiente de test. En el post de hoy, se verá un ejemplo concreto de técnicas para aprovechar estos seams . En particular, para un proyecto Arduino sencillo. Como punto de partida, considérese el siguiente proyecto Wokwi . Contexto: Wokwi es un sitio que permite crear proyectos Arduino en un navegador web, sin necesidad de placas físicas. Permite insertar y conectar componentes virtuales, y escribir código Arduino ...