Skip to content

Functionality of Stream class should not be mocked by default #135

Open
@lasselukkari

Description

@lasselukkari

First of all, thanks for putting together this amazing project! It has been really useful for me.

Here is my situation. I have a class that inherits the Stream by wrapping another instance of a Stream. I do this so that my code works with any Stream input like Wifi, Ethernet and Serial without any changes. It also makes it compatible with anything else that expects a Stream like JSON parsers and so on. The Stream base class should the same on every Arduino. This is the key feature to write cross platform libraries for all Arduinos.

Because this project implements a non standard Stream where some of the expected functions are missing or mocked with the "GODMODE" testing anything that uses the Stream is impossible. For example, any class that is derived from the Stream should be able to access the protected Stream function timedRead or set the _timeout property.

I believe the Stream class should be left as it is with the real platforms. To be honest, in my opinion all the mocks for classes that are derived from Print, Stream or Client are rather pointless. Instead people should write their code to work with the base classes and for testing a mocked class that implements the virtual functions should be used instead. This is the standard practice to write testable code but now it is impossible. I feel that this decision actually encourages bad programming practises. Maybe providing mock for the HardwareSerial is useful because that is normally used directly but atleast the Stream should stay as it is.

I had to fork this project to be able to move forward. I'm fine with that. I just feel that this may cause problems for many others too and may be the wrong approach.

What are your thoughts on this? Have a nice weekend!

Metadata

Metadata

Assignees

No one assigned

    Labels

    arduino mocksCompilation mocks for the Arduino librarybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions