Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Testing Database with QTest
Forum Update on Monday, May 27th 2025

Testing Database with QTest

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 5.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peggy
    wrote on last edited by
    #1

    Hello,

    I would like to write some QTest for database class, like connecting to database, insert tables , data.... I am beginner in this field and don't have a clue how should I start with it. I read some articles which mostly were about testing GUI. But they did not help me so far. I appreciate someone who could give me further information.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Suths
      wrote on last edited by
      #2

      I would recomend you have a look at -> voidrealms.com

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Peggy
        wrote on last edited by
        #3

        Suths thanks for the suggestion.
        But I still could not find QTest example. I know how to connect to database and get the query from but I don't know how am I supposed to write some QTest(UnitTest) for it. :(

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuhamedAuda
          wrote on last edited by
          #4

          Did u read chapter 16: Unit Testing in the Book: Foundations of Qt Development ?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sptrakesh
            wrote on last edited by
            #5

            Not related to databases, but the same type of concepts apply to testing as with anything else. Take a look at the tests under

            http://kenai.com/projects/mongoviewer/sources/svn/show/bson/trunk/src/test?rev=140

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Peggy
              wrote on last edited by
              #6

              Thank you MuhamedAuda for introducing the Book. I have read the UnitTest chapter. The first test I wrote is as following:

              @
              void TestDBMethods::testConnection(){

              QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
              db.setDatabaseName("test");
              db.setHostName("localhost");
              db.setUserName("************");
              db.setPassword("************");
              QVERIFY(db.isValid());
              QCOMPARE(db.isOpen(), true);
              

              }
              @

              in the normal case my connection will be established but in this case I got fail by QCOMPARE. Could anyone tell me where my error is?

              Question: what are the alternatives for testing the methods of another subproject in my test project?

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Peggy
                wrote on last edited by
                #7

                Ok I got my error.

                I have to write @QCOMPARE(db.open(), true)@

                But I still am looking forward to any suggestions that may help me to test the methoes of other subprojects in my test projects.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved