在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。它能找出触发测试的信号/插槽的名称吗?
答案 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;
}
}
。