我在 QT5 中使用 QT 测试,并注意到他们的文档(https://doc.qt.io/qt-5/qttestlib-tutorial1-example.html#writing-a-test)中没有使用自定义(非-QT) 命名空间,实际上甚至没有引用 QT 命名空间。
我尝试使用命名空间,考虑到这对 c++ 来说是更好的做法,但随后测试无法正常工作。
这是 QT 文档提供的第一个示例: https ://code.qt.io/cgit/qt/qtbase.git/tree/examples/qtestlib/tutorial1/testqstring.cpp?h=5.13
//! [0]
#include <QtTest/QtTest>
class TestQString: public QObject
{
Q_OBJECT
private slots:
void toUpper();
};
//! [0]
//! [1]
void TestQString::toUpper()
{
QString str = "Hello";
QCOMPARE(str.toUpper(), QString("HELLO"));
}
//! [1]
//! [2]
QTEST_MAIN(TestQString)
#include "testqstring.moc"
//! [2]
使用命名空间我创建了在使用 QT 测试时应该做的事情还是不必要的?