我是C++的新手,正在用PlatformIO & VS代码在MacOS 11.6.5上为Arduino开发。
在PlatformIO文档之后,我设置了这样一个简单的测试:
#include <unity.h>
#include <iostream>
void test_something()
{
std::cout << "Test running..." << std::endl;
TEST_ASSERT_TRUE(true);
}
int main(int argc, char **argv)
{
UNITY_BEGIN();
RUN_TEST(test_something);
UNITY_END();
}当我运行platformio test --environment local时,我在终端中看到测试结果,但没有看到std::cout的输出。
(我在不使用PlatformIO的时候发现了一个PlatformIO的例子,PlatformIO回购有大量的测试实例,但这些都不涉及cout。)
另外,VS代码IntelliSense抱怨‘不能开放源代码文件“”iostream“,但我猜这是无关的,因为PlatformIO似乎没有编译它的问题。
任何指导者都会感激的!
发布于 2022-05-28 18:48:57
好的,由于@Ulrich Eckhardt的帮助,我只需要为Unity指定--verbose模式,即:
platformio test --environment local --verbose然后有很多方法可以写到终端:
cout << "Hello" << endl;
cout << "Hello\n";
fprintf(stdout, "Hello");
putchar('a');还有一些统一打印方法,不确定这些方法的优缺点:
UnityPrint("Hello");
UnityPrintLen("Print this, but not this", 10);
UNITY_OUTPUT_CHAR('a');https://stackoverflow.com/questions/72414432
复制相似问题