How to run unit test after compilation

Hello

I want to run my unit test after the compilation process is complete.is there any way in platform io, where we define some flag for unit test in platformio.ini file to run the test after compilation process.

Thanks in advance

1 Like

No, compile and unit test are two separate project tasks accessible by two separate buttons.

Either execute it on the CLI with

pio run ; pio test

(; is assuming PowerShell, && otherwise)

Or create your own command shortcut that does the same as above.

Thank you for your reply

can you help me with some example to creat command shortcut for pio test and pio run

What code have you tried? The documentation is very clear.

i try to make the extra script for pio run but I have no idea how to make extra script for pio test.

This is extra script for project which use in github

Import(ā€œenvā€)

build_tag = env[ā€˜PIOENVā€™]

env.Replace(PROGNAME=ā€œfirmware_%sā€ % build_tag)

if you have a example for make extra script for unit test please share.

Iā€™m using

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
extra_scripts = unit_test_after_compilation.py
; change this to your actual COM port where the ESP32 board is
test_port = COM4
Import("env")

env.AddCustomTarget(
    name="build_and_test",
    dependencies=None,
    actions=[
        "pio run -e %s" % env["PIOENV"],
        "pio test -e %s" % env["PIOENV"]
    ],
    title="Build & Unit Test",
    description="Trigger the compilation and unit test "
)

to create the custom task ā€œBuild & Unit Testā€,

grafik

~~but Iā€™m currently running to Unit Testing not working on ESP32 (test port not automatically recognized) Ā· Issue #4076 Ā· platformio/platformio-core Ā· GitHub I just had to specify the test_port in the platformio.ini, itā€™s working now.

Hello @maxgerhardt
thanks for your solution and I want to learn more about extra scripts.
Can you suggest to me any tutorial about the extra script with a great explanation?

This plus the offical docs I linked to plus the code for a platform (e.g., platform-espressif32) plus the SCons documentation linked in the post.