zoukankan      html  css  js  c++  java
  • Qt单元测试


    单元测试之作用
    要完成测试用例,保证设计上的耦合依赖
    通过测试用例,保证覆盖率,提高程序质量

    QTest一些有用的静态函数
    QTest::qExec
    QTest::qSleep
    QTest::qWait
     
    例子
    .pro项目文件中加入
    QT += testlib

    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv);
        SelfUnitTestClass tc;
        MyUnitTest mt;
        QTest::qExec(&mt);
        return QTest::qExec(&tc, argc, argv);
    }

    class MyUnitTest : public QObject
    {
        Q_OBJECT       
    private Q_SLOTS:
        void toUpper_data();
        void toUpper();
    };

    void MyUnitTest::toUpper_data()
    {
        QTest::addColumn<QString>("string");
        QTest::addColumn<QString>("result");

        QTest::newRow("all lower") << "hello" << "HELLO";
        QTest::newRow("mixed")     << "Hello" << "HELLO";
        QTest::newRow("all upper") << "HELLO" << "HELLO";
    }

    void MyUnitTest::toUpper()
    {
    //    QString str = "Hello";
    //    QVERIFY(str.toUpper() == "HELLO");
         //数据驱动
        QFETCH(QString, string);
        QFETCH(QString, result);
        QCOMPARE(string.toUpper(), result);
    }
     
    #define private public/protect

    //all private method is under private slots
    Foo a;
    QMetaObject::invokeMethod(&a, "Test", Qt::DirectConnection);
  • 相关阅读:
    关于父子页面的交互
    Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)
    关于Zookeeper
    Java 生成pdf表格文档
    Spring 框架中Http请求处理流程
    关于redis
    Xstream 解析xml文件内容
    ArrayBlockingQueue 和LinkedBlockQueue
    spring IOC
    springboot启动过程
  • 原文地址:https://www.cnblogs.com/danju/p/3691489.html
Copyright © 2011-2022 走看看