I currently use the platform PlatformIO and develop my own library. For it, I intend to use the pio unit testing, but unfortunately it is troublesome. The necessary code is below:
test/test_unit.cpp #include
#include "../src/models/unit.h"
// void setUp(void) {
// // set stuff up here
// }
// void tearDown(void) {
// // clean stuff up here
// }
void test_unit_printable(void) {
String prefix = "K", unit = "m";
const char* expected = "Km";
const char* actual;
BaseUnit bunit(prefix, unit);
String bunit_p = bunit.printable();
actual = bunit_p.c_str();
TEST_ASSERT_EQUAL_STRING(expected, actual);
}
void setup() {
UNITY_BEGIN();
RUN_TEST(test_unit_printable);
UNITY_END();
}
void loop() {
}
src/models/unit.h
#ifndef UNIT_H
#define UNIT_H
#include "Arduino.h"
class BaseUnit {
public:
BaseUnit() {};
BaseUnit(String prefix_, String label_);
~BaseUnit() {};
String printable();
public:
String prefix;
String label;
};
#endif
src/models/unit.cpp
#include "unit.h"
BaseUnit::BaseUnit(String prefix_, String label_){
prefix = prefix_;
label = label_;
}
String BaseUnit::printable(){
return prefix + label;
}
Error during test:
/tmp/ccI0alHK.ltrans0.ltrans.o: In function `test_unit_printable()':
ccI0alHK.ltrans0.o:(.text+0x58a): undefined reference to `BaseUnit::BaseUnit(String, String)'
ccI0alHK.ltrans0.o:(.text+0x5a8): undefined reference to `BaseUnit::printable()'
Aucun commentaire:
Enregistrer un commentaire