QTest获得测试名称

时间:2016-09-19 16:55:05

标签: c++ qt qtestlib

在Qt单元测试中,程序如何检索正在运行的测试的名称?

代码看起来像这样:

#include <QtTest>
class MyTest : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void initTestCase()
    {
    }

    void testCase1()
    {
    }

    void cleanupTestCase()
    {
      // Want to print "finished testCase1" here
    }
};

QTEST_APPLESS_MAIN(MyTest)

e.g。它能找出触发测试的信号/插槽的名称吗?

1 个答案:

答案 0 :(得分:1)

QTest::currentTestFunction()应将当前测试函数的名称作为cleanup

返回

顺便说一下,也许你想把它放在cleanupTestCase函数中,而不是cleanup?每次测试后都会调用cleanupTestCase,而只有在完成所有测试后才会调用#include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <stdio.h> int main() { int pid; int i; pid = fork(); switch(pid) { case -1: perror ("Error \n"); break; case 0: for(i=1; i < 11; i++) printf ("Im the son %d, My father is %d - Loop %d \n", getpid(), getppid(), i); break; default: for(i=1; i < 11; i++) printf ("Im the father %d and my father is %d - Loop %d \n", getpid(), getppid(), i); wait(NULL); printf("End of the father process %d - My son process %d have finished.\n", getpid(), pid); break; } }