Skip to content
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

UnitTesting example calculator file/folder layout seems only to work with single component in native and embedded environment #43

Open
dfch opened this issue Jul 28, 2023 · 6 comments

Comments

@dfch
Copy link

dfch commented Jul 28, 2023

The unit testing example calculator aims to show how to use unit testing with native and embedded environments (with the Unity testing framework). The suggested file/folder structure and the contents of the test components test_embedded and test_desktop however only seem to work with a single test file - due to the definition of main and setup/loop. When adding multiple test files with that structure we certainly get compilation errors like this:

multiple definition of `main'; .....cpp:(.text+0x5f): first defined here

Besides the setUp and tearDown function will cause duplicates as well. It seems that one would have to move the main function to a separate file and reference all the other tests from there.

I am just pointing this out, as the file/folder structure after such a change would differ greatly from the example and the accompanying documentation. And this - imo - makes it a mediocre example.

I would like to see a unit test example that can easily be extended and be used in a real life project. Maybe I am missing something here, then pls tell me so and I am more than happy to delete/close this issue.

Thank you for your help and support.

@ivankravets
Copy link
Member

@dfch
Copy link
Author

dfch commented Jul 28, 2023

yes, I have read it. But obviously, I must have missed sth, otherwise you would not have asked ...

I now adjusted the platformio.ini with this (and the folder structure):

  • --- envNative
    | for native / desktop tests
  • --- envEmbedded
    | for embedded tests
[platformio.ini]

[env:esp32...]
test_ignore = envNative/*

[env:native]
test_ignore = envEmbedded/*

This gets me all embedded test skipped when building native and the other way round.

However, I still have the problem, I cannot have more than one test file in a single test_... folder (without name clashing/redefines).

Does the documentation really state, to have only one test file per folder? that in turn would mean, I would have to combine all the tests for a lib in a single test file - or have multiple folders for one component.

Pls do get me right - I am not complaining. It is just, that I would have hoped that the example would be a little bit more comprehensive or adjustable. I would be interested in the best current practice from PlatformIO's point of view on how to do this. And an easy thing would be to express that view via one of the examples.

You can easily close the issue and I will find a workaround for myself.

Thanks anyway for the quick reply and the good work on PlatformIO.

@dfch
Copy link
Author

dfch commented Jul 28, 2023

@ivankravets I got a working example for myself (Unity and ESPIDF (not Arduino)) and could contribute this here, if interest exists.

@ivankravets
Copy link
Member

Hi Ronald,

Thanks for your feedback! Of course, we would be happy if you help us improve documentation and examples. Could you provide a PR?

@dfch
Copy link
Author

dfch commented Jul 31, 2023

Yep, will do so.

@dfch
Copy link
Author

dfch commented Aug 8, 2023

@ivankravets Sorry for taking so long, but there was sth I had to handle with more priority. I am ready to submit the PR and just wanted to know what the contents of the license header/file should be. Thank you for your advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants