我目前使用PlatformIO平台并开发自己的库。为此,我打算使用pio单元测试,但是很麻烦。必要的代码如下:
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;
}
测试过程中的错误:
/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()'