×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    passing arguments to my qttestlib class

    I am using QTest::qExec to start my qttest class like so
    QTest::qExec(test, argc, argv);

    How do I retrieve or use the parameters (argc and argv) from inside the QTTestclass, I tried to modify the constructor to accept them but it gives me "illegal default arguments"?

    class myQTestClass: public QObject
    {
    Q_OBJECT

    public :
    myQTestClass(QWidget *parent = NULL) ;

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: passing arguments to my qttestlib class

    Why would you need to pass command line arguments to your test class?

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Re: passing arguments to my qttestlib class

    Basically I have this function inside my testclass that needs to run with a specific string.
    I want it to run using a filename specified. So I would like to be able to pass a filename as a QString to that test function. My plan was to run it like below however I have a feeling this is not exactly how this works as filename.txt is actually supposed to be a test data? How can I do this?

    myApp.exe -myFunc:filename.txt -myfunc:filename2.txt -myfunc:filename3.txt

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: passing arguments to my qttestlib class

    I didn't get why passing parameters to constructor may fail. Any way it's conceptually wrong to pass parameters to unit tests, since they are supposed to be the same every run to ensure stability of implementation code.
    Code:
    #include <QtTest/QtTest>
    #include <QtCore/QDebug>
    
    class TestQString: public QObject
    {
        Q_OBJECT
    public:
        TestQString(QObject *parent = 0, int argc = 0, char ** argv = 0);
    private slots:
        void toUpper();
    };
    
    TestQString::TestQString(QObject *parent, int argc, char ** argv)
        : QObject(parent)
    {
        qDebug() << argc << argv;
    }
    
    void TestQString::toUpper()
    {
        QString str = "Hello";
        QCOMPARE(str.toUpper(), QString("HELLO"));
    }
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        QTEST_DISABLE_KEYPAD_NAVIGATION
        TestQString tc(0, argc, argv);
    
        return QTest::qExec(&tc, argc, argv);
    }
    #include "testqstring.moc"

  5. #5
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    430

    Re: passing arguments to my qttestlib class

    You might also have a loot at http://qt.nokia.com/doc/4.6/qtestlib-tutorial2.html
    If you read your test data from a file, you have a clean way to alter the test execution.

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: passing arguments to my qttestlib class

    Quote Originally Posted by axeljaeger View Post
    You might also have a loot at http://qt.nokia.com/doc/4.6/qtestlib-tutorial2.html
    If you read your test data from a file, you have a clean way to alter the test execution.
    I think altering test execution is very much against the idea of unit testing. In case subset of tests has to be executed, there are command line arguments:
    http://qt.nokia.com/doc/4.6/qtestlib...line-arguments

Similar Threads

  1. Issue when trying to generate .sis file
    By rmulam in forum Symbian Tools & SDKs
    Replies: 9
    Last Post: 2009-08-13, 14:10
  2. Replies: 11
    Last Post: 2009-05-04, 07:24
  3. passing arguments
    By niff111 in forum Symbian
    Replies: 8
    Last Post: 2009-02-18, 12:18
  4. Need one HTTP client example
    By vinayakak in forum Symbian Networking & Messaging (Closed)
    Replies: 15
    Last Post: 2008-01-06, 06:44
  5. Passing arguments
    By franalegre in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-04-23, 11:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×