Coder Social home page Coder Social logo

espmock's Introduction

EspMock

AUnit Tests

Mocks for various ESP8266 functions and libraries, designed to be used under EpoxyDuino which provides the Arduino programming API on a Linux, MacOS or FreeBSD environment.

The WiFi simulation can manage many virtual devices so it is possible to write unit tests between many Esps.

This project was originally created to run AUnit unit tests for the TinyMqtt library, but it can be useful for any other project that needs mocks for ESP8266 and ESP32 libraries.

Installation

You must install the following projects:

These projects cannot be installed through the Arduino Library Manager because they are not normal Arduino libraries. It is probably most convenient to install them in the same location as other Arduino library directory. In other words, locate the ./libraries/ directory of your sketchbook directory used by the Arduino IDE, and run the following commands:

$ cd {SketchBookDirectory}/libraries
$ git clone https://github.com/bxparks/EpoxyDuino
$ git clone https://github.com/hsaturn/EspMock
$ git clone https://github.com/bxparks/AUnit

Usage

For each Arduino program, we need to create a Makefile as described in EpoxyDuino, but with a few extra parameters:

  • Add the EPOXY_CORE variable with the value EPOXY_CORE_ESP8266.
  • Add a ARDUINO_LIB_DIRS variable that points to {EspMockDirectory}/libraries directory to pickup additional ESP8266 or ESP32 mock libraries provided by EspMock.

The result is a Makefile that looks like this:

APP_NAME := {NameOfSketch}
ARDUINO_LIBS := {Lib1} {Lib2} ...
ARDUINO_LIB_DIRS := {EspMockDirectory}/libraries
EPOXY_CORE := EPOXY_CORE_ESP8266
include {EpoxyDuinoDirectory}/EpoxyDuino.mk

See tests/network-tests/Makefile for a concrete example.

License

MIT License

Authors

espmock's People

Contributors

bxparks avatar hsaturn avatar

Watchers

 avatar  avatar

espmock's Issues

add Usage instructions to README.md

@hsaturn: Please take a look at the updated README.md if you haven't already seen it. And I updated https://github.com/bxparks/EpoxyDuino#LibrariesAndMocks subsection to reference this project.

I wanted to add a Usage section in this README.md with instructions on how to use EspMock, but when I looked at your code, I got confused. There is an Arduino.h file under src/, but that doesn't make sense, since it would cause multiple Arduino.h to appear to the compiler. I think this file can be removed.

I think your intention was to make the EspMock library transparent, once it is included in the ARDUINO_LIBS variable of the EpoxyDuino's Makefile. I think most programs which are designed to work under both ESP32 and ESP8266 have this little bit of header file machinery:

#if defined(ESP8266)
  #include <ESP8266WiFi.h>
#elif defined(ESP32)
  #include <WiFi.h>
#else 
  #error Unsupported platform
#endif
#include <WiFiUdp.h>
...

When compiling such a program under EpoxyDuino, the preprocessing will fail, so I think this needs to be updated to something like this:

#if defined(ESP8266)
  #include <ESP8266WiFi.h>
#elif defined(ESP32)
  #include <WiFi.h>
#elif defined(EPOXY_DUINO)
  #include <ESP8266WiFi.h>
#else 
  #error Unsupported platform
#endif

It is currently not possible to tell EpoxyDuino to "compile the ESP8266 flavor of EpoxyDuino", or "compile the ESP32 flavor of EpoxyDuino". In my mind, EpoxyDuino should be considered to be a separate, independent implementation of the Arduino API. When various networking libraries are added, I think they should be self-contained within the EpoxyDuino environment. Ideally, the names of these mock libraries would not contain "ESP8266" within them, because they are targeting the EpoxyDuino environment.

On the other hand, there are certain ESP8266 libraries that you are mocking out, specifically to make sure that your programs that you wrote for ESP8266 compile properly using a Linux environment. I'm not entirely sure how to organize these libraries so that it makes sense to us, and to potential users of EspMock.

[Edit: fix typos]

Missing WProgram.h

Moved from bxparks/AUnit#75


Hi Brian

My unit tests are broken due to WProgram.h missing (here)

This files has gone when I have acecpted your PR on EspMock.

I may be wrong as this is the first time I'm using EPOXY_CORE as I wanted my unit tests to pass since this modification.

Best regards


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.