Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Writing Unit Tests with QtTest that access objects in another project
Forum Updated to NodeBB v4.3 + New Features

Writing Unit Tests with QtTest that access objects in another project

Scheduled Pinned Locked Moved Qt Creator and other tools
5 Posts 2 Posters 4.0k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    mark_in_gr
    wrote on last edited by
    #1

    I have a fairly large QT Project in QT Creator where I wish to test various functions. It appears that there is no easy way, however, to create the unit tests in the same project that the tested objects reside. This is creating numerous problems, including the need to create either a static lib and link to that from the unit test project, or list each .obj file in the LIB var. Either is impractical.

    So I created a separate project to hold the first group of Tests using QtTest. But I was wondering how other people structure this sort of thing. Ideally, I would want to have the unit tests in the same project, but that doesn't seem possible because it looks like the only way to invoke the tests is either through the QTEST_MAIN macro or qexec().

    Has anyone successful done something like this?

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

      I have been following the same policy - separate unit test project and library projects. I usually build dynamic libraries and just link to it in the unit test project as well as specify the library project as a dependency for the test project. This is even more of an issue on Mac OS X, since you need to copy the dylib file into the unit test project build directory to satisfy the runtime loader.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mark_in_gr
        wrote on last edited by
        #3

        I was afraid that was the case. So then I suppose I will have to create either a DLL or static Library within the process that builds my project that I wish to test, so whenever the actual test project(s) is executed, it will be testing the latest code.

        This seems highly unproductive and unlike other testing frameworks I have used for other frameworks(Java, .NET).

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

          Btw, thank you for the respond! :)

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

            Yes, it is a bit different from how integrated unit testing is with Java/.NET etc., but I do not think it is that unproductive. The primary target in each of my IDE sessions is the test project. I add code to my library project, add unit test code to the test project and just hit run. Since the library project is marked as a dependency of the test project, it automatically builds the library and then builds and executes the tests. The end result is you get most of the same type of integration as with Java/.NET

            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