Skip to content

Adding several serial functions and unit tests for all print and println functions #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 18, 2015

Conversation

frznlogic
Copy link

Added mocking for:

  • Serial::read,
  • Serial::available,
  • Serial::write
  • A new helper class stringCapture which simplifies getting all data from Serial functions, or other functions for that matter. This helps when testing code with arbitrary number of calls to Serial functions, but where the "sent" string is known (ie, you know how the protocol should look, but don't care how it is created).

Unit tests are added for almost all functionality, and also updated to cover all print/println functions.

Oscar Andreasson added 7 commits January 3, 2015 14:54
Added function Serial_::available()
Added mocking for functions
Added tests for read and available
Added tests for all print and println functions
…eral Serial calls.

* Added more tests for stringCapture class
@frznlogic frznlogic changed the title Adding Serial::read and Serial::available and unit tests for all print and println functions Adding several serial functions and unit tests for all print and println functions Jan 12, 2015
* tests in test/serial_unittest.cc
*
*/
class stringCapture {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need stringCapture here?
I think ... it is not mock for Arduino.

It is a helper class for our UnitTest, isn't it? If so, please move this one to '/test' directory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ikeasu, I wrote a longer response below. The stringCapture stuff is supposed to be used by external testers. The naming is a bit bad, any thoughts on a new name?

@ikeyasu
Copy link
Owner

ikeyasu commented Jan 12, 2015

Good job!
My comment is only one for a position where we should have stringCapture.
It seems a helper function for arduino-mock's unittest, so it should be locate in /test?

@frznlogic
Copy link
Author

Hi Ikeyasu!

Thanks! I really appreciate the project fyi, I've been looking for a good mocking system of the arduino platform for a long time as it is fairly hard to test on the platform itself :).

Anyways, back to topic, the stringCapture class is supposed to be used by external users. I'm currently using it in a private project to verify functions which calls Serial::write arbitrary number of times and where I don't want to rely on the internal implementation of the function, but the outcoming stream format is really important. In this testcase, I encode it using the arduino functions, then I decode it using the PC side decoder within the unit test/mock framework.

@ikeyasu
Copy link
Owner

ikeyasu commented Jan 14, 2015

Thank you for your reply.
I would like to improve Arduino testing framework. (You know the current Arduino testing is very poor..)

I'm currently using it in a private project to verify functions which calls Serial::write arbitrary number of times and where I don't want to rely on the internal implementation of the function

You mean you are using it as a library for your Arduino project?
If so, please consider to separate the class to another header file.
I understood that It is necessary but I would like to keep a structure of 'serial.h' as same as Arduino's library.

@frznlogic
Copy link
Author

Fair enough. I've moved the functions into a file called serialHelper.cc/h and serialHelper_unittest.cc. Makefiles have been updated. Is this better?

@ikeyasu ikeyasu merged commit 774d303 into ikeyasu:master Jan 18, 2015
ikeyasu added a commit that referenced this pull request Jan 18, 2015
Adding several serial functions and unit tests for all print and println functions

Conflicts:
	test/Makefile
@ikeyasu
Copy link
Owner

ikeyasu commented Jan 18, 2015

LGTM. It was merged manually.
Thanks a lot.

@frznlogic
Copy link
Author

Thank you :)

jonathanperret pushed a commit to jonathanperret/arduino-mock that referenced this pull request Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants