#96 QT's QObject and unit testing

-- deleted --
closed-invalid
nobody
5
2004-03-13
2003-07-24
Bob Tanner
No

class MyTest : public QObject, public CppUnit::TestFixture {
Q_OBJECT
public:
MyTest();
virtual ~MyTest();
public slots:
void slotFooBar();
private:
bool myBool'

CPPUNIT_TEST_SUITE(MyTest);
CPPUNIT_TEST(testNotify);
CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(MyTest);

Because QT's moc compile will make a MyTest.moc.cpp, the test
register get's called 2 times, thus running each test 2 times.

Not sure if this is a QT problem or cppunit problem.

Discussion

  • Logged In: YES
    user_id=196852

    You should never put CPPUNIT_TEST_SUITE_REGISTRATION
    macro in a header file. This macro declare a static variable
    that will automatically register the test at startup time.

    Since Qt moc will also include your header, the test will be
    registered twice.

    Just move the macro to your cpp file and you will be ok.

    Baptiste.

     
    • status: open --> closed-invalid