Posts

Showing posts from April, 2023

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

New syntax highlighter: PrismJS

Spanish version / Versión en Español Who would have thought that this blog would live long enough to see a third change of syntax highlighter? Incredibly enough, Blogger is also alive and kicking. This site's administration has decided to retire highlightjs , which seems to be still alive, but has lost ground to prismjs . Obviously, it's subjective, but personally I have decided to favor Prism due to the following reasons: It managed to handle VB.NET code blocks better. Yes, I know it's not the most modern language, but we still hold some affection for it. It looks better: it's more compact, with a better color selection. It also highlights more keywords, at least for the languages we use here. It offers an extensible architecture, including a plugin system which allows, for example, adding line numbers. HighlighJS has no such feature. All of these extra features, and still Prism has a very small footprint. Without fu

Nuevo resaltador de sintaxis: PrismJS

Versión en inglés / English version ¿Quién habría pensado que este blog viviría lo suficiente para ver un tercer cambio de resaltador de sintaxis? Increíblemente, también Blogger sigue vivo y coleando. La administración de este sitio ha decidido jubilar a highlightjs , que parece seguir con vida, pero ha perdido terreno ante prismjs . Obviamente es una cuestión subjetiva, pero personalmente me he decantado por prism por los siguientes motivos: Logró resaltar mejor los bloques de código VB.NET. Sí, sé que no es un lenguaje muy moderno que digamos, pero lo queremos igual. Se ve mejor: más compacto y con mejor selección de colores. También destaca más palabras. Ofrece una arquitectura extensible, incluyendo plugins para, por ejemplo, agregar números de línea. HighlightJS carece de esto. Todo esto y más, con un tamaño muy pequeño. Sin más preámbulo, veamos los pasos para empezar a usar prims en Blogger: En Blogger, seleccionado