How to set a testing environment?

When I press build, I don’t want the native testing environment to be built, because obviously it will fail.

When I press test, I don’t want the Arduino environments to be tested, because obviously they will fail

This is impossible apparently?

default_envs applies to both
image

builds fail

tests fail
image

Are you sure you have the correct environment selected in the the project enviornment selector? When you press test or build, it should only do that for the currently selected environment.

Unless you’re using the project task “Default->Build All” / “Default → Advanced → Test all”.

The environment is set to “Default” which builds all environments by default. Do I have to manually switch every time I want to run tests and build?

You can keep the selected environment as uno and use the testing sidebar to run tests for native without switching.
grafik

You can also disable tests in the uno environment using test_filter per this.

The testing sidebar doesn’t work

Testing passes when clicking the small “test” button

But fails when using the sidebar
image

Works for me in my projects.

Are you sure you have the PlatformIO extension up-to-date and no conflicting extensions installed?

I’m using the latest version 3.1.1
image

As for conflicting extensions, if I disable every extension except for the required ones, it still fails

Does this maybe have something to do with the python version it is using? Since the error seems to complain about something python related

Can you post a minimal project with Uno + Native environments that fails build for native and fails test for Uno like yours?

If you create an empty project with this main.cpp


this test file

and this platform.ini

It fails to build for Native because it can’t find Arduino.h
I don’t actually know why testing fails on the uno for my other project, it works fine in the empty project, but either way the testing sidebar still fails

Please, instead of screenshots, could you upload the project as a .zip file somewhere?

https://drive.google.com/file/d/11-13A94jWNbmg4SyVTfvKRWv_im0E4_J/view?usp=share_link

You’re not using the right folder structure at all, so tests are not correctly recognized.

See reference project and documentation.

When I order the project files as

grafik

And, same as the reference project, use test_ignore to not make uni environment execute the native tests, using the platformio.ini

[env:Native]
platform = native
test_ignore = test_embedded ; if there were some in the future

[env:uno]
platform = atmelavr
board = uno
framework = arduino
test_ignore = test_native

and reload the VSCode window (Ctrl+Shift-P → Reload Window), I get a nice

grafik

I.e…, no tests executed for Uno, and tests for native passed.

2 Likes

See project

https://drive.google.com/file/d/1O3fWu1pmkMhgNDvAwSTGccuTgZueBrLR/view?usp=sharing

I see, thank you for the clean solution

I was following

which didn’t really specify the location for the test file so I assumed it was fine

The tutorial is outdated since Testing got majorly refactored in PIO core 6 version. Seems like it wasn’t updated since then.

1 Like