Do embedded programming with test-driven development with googletest

Introduction

[Amazon.co.jp: Embedded programming with test-driven development-Agile design learned in C language and object orientation](https://www.amazon.co.jp/%E3%83%86%E3%82%B9 % E3% 83% 88% E9% A7% 86% E5% 8B% 95% E9% 96% 8B% E7% 99% BA% E3% 81% AB% E3% 82% 88% E3% 82% 8B% E7 % B5% 84% E3% 81% BF% E8% BE% BC% E3% 81% BF% E3% 83% 97% E3% 83% AD% E3% 82% B0% E3% 83% A9% E3% 83 % 9F% E3% 83% B3% E3% 82% B0-% E2% 80% 95C% E8% A8% 80% E8% AA% 9E% E3% 81% A8% E3% 82% AA% E3% 83% 96% E3% 82% B8% E3% 82% A7% E3% 82% AF% E3% 83% 88% E6% 8C% 87% E5% 90% 91% E3% 81% A7% E5% AD% A6% E3% 81% B6% E3% 82% A2% E3% 82% B8% E3% 83% A3% E3% 82% A4% E3% 83% AB% E3% 81% AA% E8% A8% AD% E8% A8% 88-James-W-Grenning / dp / 4873116147)

This article is the first in a series that aims to prevent people who start learning using the above books from stumbling in environment construction.

I am developing embedded systems and mainly use C language. Before I came across this book, every time I modified the code, I cross-built it and copied the binaries to the target board to see how it worked. Since the hardware is not enough for the team staff, when other members are using the hardware, it was not possible to check the operation and development was often delayed.

In February of this year, I came across this book and started to practice what was written in my work. As a result, my development style has changed dramatically. With a dual-target build environment, you can now do unit test-based development on your host without any hardware, and automated unit testing makes it easy to spot small mistakes. I have come to have a little bit of quality in the code I wrote.

Now, all the new features we add are developed in TDD, we find time to write tests in existing locations and continue to refactor mercilessly. I feel that the code has evolved into a better design that is easier to read with each modification.

This book introduces Unity and CppUnit as testing frameworks. I thought that there was no trick to do it as it is, and there was a stumbling block when studying this book, so this time I decided to publish the source code that I can start studying this book immediately using google test.

Autotools is used as the build tool. Therefore, the published source code can be cross-built as it is with a cross-compiler. googletest works without installation, so if you pop the cross-built binary on the target board, the unit test will run on the target board.

What I stumbled upon in learning

While reading this book, I tried to copy sutras using Unity and CppUnit, but I was ashamed to say that I stumbled on the environment construction ... (I've forgotten why I stumbled, but I think I was fighting for about a day for some reason) Also, with the published sample code, the build script was complicated (for me) and I couldn't easily want to extend it myself. It's a small thing, but if you stumble on something other than what you want to learn, it's easy to lose your motivation to learn.

I tried to create an environment where even people who have just entered the embedded industry can add files and copy sutras by themselves.

Source code

The source code is below. https://github.com/tomoyuki-nakabayashi/TDDforEmbeddedC

The product code and test code at the end of Chapter 4 are released. If you have git, gcc and autotools installed, you can run the test in less than a minute.

If you want to copy this book from the beginning, please delete the contents of src / LedDriver.c, src / LedDriver.h, test / LedDriverTest.cpp.

Add source file

If you want to add the source file yourself and try various things, please add the file name in the corresponding part of the following file. TDDforEmbeddedC/test/Makefile.am

test_sources = \
  TestMain.cpp \
  LedDriverTest.cpp
target_sources = \
  $(top_srcdir)/src/LedDriver.c
gtest_SOURCES = $(test_sources) $(target_sources)

Test double and mock

Chapters 7 and beyond of this book cover the story of test doubles and mock. For the rest of the content, we have created an environment where you can easily start copying sutras.

Embedded programming by test-driven development with google test Chapter 8 Embedded programming by test-driven development-mock & flash driver- Embedded programming by test-driven development with google test-SOLID design-

Postscript

Added support for CMake.

Recommended Posts

Do embedded programming with test-driven development with googletest
Do embedded programming by test-driven development with google test-SOLID design-
Do embedded programming with test-driven development with googletest
Do embedded programming by test-driven development with google test-SOLID design-
What you can do with programming skills
What you can do with programming skills
Development digest with Django
Asynchronous programming with libev # 2
3. 3. AI programming with Python
Python programming with Atom
Competitive programming with python
Shader programming with pyOpenGL
Do Houdini with Python3! !! !!
Asynchronous programming with libev
Linear Programming with PuLP
Programming with Python Flask
Asynchronous programming with libev # 3