platformio / platformio-examples

PlatformIO Project Examples
Apache License 2.0
581 stars 175 forks source link

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

Open dfch opened 1 year ago

dfch commented 1 year ago

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 commented 1 year ago

Have you read https://docs.platformio.org/en/latest/advanced/unit-testing/structure/index.html ?

dfch commented 1 year ago

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):

[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 commented 1 year ago

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

ivankravets commented 1 year ago

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 commented 1 year ago

Yep, will do so.

dfch commented 1 year ago

@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.