Naming a constant value before compilation

I have a sketch with some constant values depending on the board.
For testing purposes this value would be "Testboard".
When I'm done testing I want to change "Testing" into for example "Boat".
A few of those sketch lines look like this:

WiFi.setHostname("Testboard");
message = "ESP32C6 Testboard has restarted";
mqtt_client.publish("Testboard/Webasto/status", "ON", true);
if (mqtttopic == "Testboard/AllSensorUpdateFreq") {

Is there a kind of "#define" which can be used to accomplish this?

Have you considered the #ifdef

#ifdef TEST_MODE

WiFi.setHostname("Testboard");
message = "ESP32C6 Testboard has restarted";
mqtt_client.publish("Testboard/Webasto/status", "ON", true);
if (mqtttopic == "Testboard/AllSensorUpdateFreq") {

#else

WiFi.setHostname("secret");
message = "ESP32C6 real board has restarted";
mqtt_client.publish("Webasto/status", "ON", true);
if (mqtttopic == "AllSensorUpdateFreq") {

#endif

A #define TEST_MODE in the top of your sketch (commented or not) selects the piece of code that gets into the compilation process.

you can use @robtillaart idea but to have #define for the name

#define TEST_MODE 1 // change to 0 if you want production mode

#if TEST_MODE
#define HOSTNAME "Testboard"
#else
#define HOSTNAME "Boat"
#endif

then you can benefit from the fact that adjacent string literals are concatenated at compile time after macro expansion

WiFi.setHostname(HOSTNAME);
message = "ESP32C6 " HOSTNAME " has restarted";
mqtt_client.publish(HOSTNAME "/Webasto/status", "ON", true);
if (mqtttopic == HOSTNAME "/AllSensorUpdateFreq") {

this way there is no #if in the code itself.

Yep, looked at that option but as I have 43 lines where the board name should be changed it would enlarge the sketch quite a bit.
If there's no other option I would rather use the find&replace method.
Thanks!

did you check my suggestion ?

Repeating something in your code 43 times sounds like something you should definitely fix! Define it once, use it 43 times, that's fine.

Sorry @J-M-L, guess your answer was posted while I was answering @robtillaart and for some reason I missed your post.
Your suggestion works!

WiFi.setHostname("Testboard");
message = "ESP32C6 Testboard has restarted";
mqtt_client.publish("Testboard/Webasto/status", "ON", true);
if (mqtttopic == "Testboard/AllSensorUpdateFreq") {

is now:

WiFi.setHostname(BOARDNAME);
message = "ESP32C6 " BOARDNAME " has restarted";
mqtt_client.publish(BOARDNAME "/Webasto/status", "ON", true);
if (mqtttopic == BOARDNAME "/AllSensorUpdateFreq") {

I tried a combination of "#define " and "strcat()" before without success.
Always came back with an error but your solution is simple and works perfectly.
Thanks all for helping :+1:

great glad it helped!

It's an old trick — the original C compiler written by Dennis Ritchie at Bell Labs already supported adjacent string literal concatenation in the early 1970s.

One key technical reason was to allow the preprocessor to generate strings in pieces as you required.

#define NAME "UART"
printf("Device: " NAME);

This mechanism avoids runtime concatenation and produces a single static string object.

Another important early motivation was source formatting. C did not originally allow multi-line string literals directly, so programmers could write

"long text part 1 "
"part 2 "
"part 3"

instead of using escape sequences or complex continuation rules.