Skip to content
/ Mock Public

Replace Arduino methods with mocked versions and let you develop code without the hardware. Run parallel hardware and system development for greater efficiency.

License

Notifications You must be signed in to change notification settings

berrak/Mock

Repository files navigation

GitHub license GitHub version GitHub issues Documentation Installation instructions Badge Hit Counter

Arduino library Mock

Replace Arduino methods with mocked versions and let you develop code without the hardware. The mocked functions return immediately or return zero. Run parallel hardware and system development for greater efficiency. Arduino's command line tool, such as arduino-cli, frees you from Arduino IDE for tests and uploads.

Why try Mock?

  • Develop software independently of any related parallel hardware project.
  • Use any development environment or your favorite editor with arduino-cli and library Mock.
  • Use existing well-known tools for debugging.
  • Reach set time goals faster in any Arduino microcontroller project.

The purpose of this library is to be a practical eye-opener on mocked object usage, at least for some early phases of the project development cycle. Another objective of mocking is to focus on avoiding logical human errors in the overall design flow of the program. Unfortunately, this problem in the code tends to be less well-tested and may end up as an end-user complaint.

Usage

Add the include path to the Mock source directory for the IDE. For example, in the Eclipse IDE, open. Project->Properties->C++ General->Paths and Symbols->Includes->Languages: Gnu C++, Include Directories: /home/bekr/Arduino/libraries/Mock/src.

At the beginning of the main.cpp file, add.

#include <Mock.h>
using namespace mock;

Pre-pend all Arduino's calls with 'Mock::', like this.

int value = Mock::analogRead(analog_read_pin);

The mocked functions return immediately or return zero. To remove all mocking fragments, run the make-demock.sh shell script (recommended method) on the file(s) to erase all added mock -fragments.

Examples

In Arduino IDE scroll down the long list below File->Examples and find Mock. An example run of the example may look like the following screen output. Note that a majority of the mocked methods return zero or return immediately. The map()-call is an exception and is defined as in Arduino.

Mock::millis(): 0
Mock::micros(): 0
Mock::delay(): NOP
Mock::delayMicroseconds(): NOP
Mock::analogRead(): 0
Mock::digitalRead(): 0
Mock::analogWrite(): NOP
Mock::analogRead(): 0
The map() return value should be ~2500: 2474
10 x Mock::digitalWrite() - LED_BUILTIN will not blink

Documentation (GitHub Pages - Doxygen)

Library documentation.

How to Install

Click on the green Library Manager badge above for instructions, or use the alternative manual installation procedure.

  1. Navigate to the Releases page.
  2. Download the latest released ZIP-archive in ~/Arduino/libraries.
  3. Unzip the archive.
  4. Rename the new directory. Remove version-code, or master in the name like this for Mock.
  5. Restart Arduino IDE.
  6. In Arduino IDE scroll down the long list below Sketch->Include Library and find Mock.

Ensure any mock-fragments are removed in the build process

In the script folder is the canonical make-demock.sh shell script for removing any mock fragments in the released code. Ensure that your Arduino installation uses the latest version of Mock.

This script uses various CLI tools, most noticeable rpl, that replace text strings in files. This tool is most likely installable with pythons pip package manager. Finally, the script use grep to ensure it does not find any mock fragments in the release code.

Run it with the file name, as the argument, like so.

make-demock.sh sketch.ino
make-demock.sh other.cpp
make-demock.sh other.h

Planned Improvements/Changes

For planned changes, improvements, and known bugs, please visit the Github issues tracker.

Other related libraries

FabioBatSilva et al. and their library ArduinoFake focus on validating methods in the project test phase.

About

Replace Arduino methods with mocked versions and let you develop code without the hardware. Run parallel hardware and system development for greater efficiency.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published