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. How to test the code from application (as opposed to library)?

How to test the code from application (as opposed to library)?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 2.1k 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I'm trying to figure out how to do automated testing with the help of Qt Test . Since a test itself is an application (.exe on Windows), testing libraries is no problem - add proper INCLUDEPATH and LIBS to the project just as if linking any other application with this library. But how do I test the code that resides in the app-type project? You can't link an application to another application.

    Do I have to directly include the source files being tested into the test project? This can be non-trivial - there may be many dependencies, including 3rd-party libraries.

    jsulmJ 1 Reply Last reply
    0
    • V Violet Giraffe

      I'm trying to figure out how to do automated testing with the help of Qt Test . Since a test itself is an application (.exe on Windows), testing libraries is no problem - add proper INCLUDEPATH and LIBS to the project just as if linking any other application with this library. But how do I test the code that resides in the app-type project? You can't link an application to another application.

      Do I have to directly include the source files being tested into the test project? This can be non-trivial - there may be many dependencies, including 3rd-party libraries.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Violet-Giraffe What tests do you want to write? Unit tests? Feature tests? System tests?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Violet-Giraffe What tests do you want to write? Unit tests? Feature tests? System tests?

        V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        @jsulm
        Feature tests, I suppose. Or unit tests. There doesn't seem to be much difference in this context. Even when I'm unit-testing a single class or even single method, it still may require a lot of dependencies that I'm not keen on duplicating in the test.pro file (but I don't see any other way).

        jsulmJ 2 Replies Last reply
        0
        • V Violet Giraffe

          @jsulm
          Feature tests, I suppose. Or unit tests. There doesn't seem to be much difference in this context. Even when I'm unit-testing a single class or even single method, it still may require a lot of dependencies that I'm not keen on duplicating in the test.pro file (but I don't see any other way).

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Violet-Giraffe For such tests you do not need your executable. Instead you create test executables where you include parts of your source code which you want to test. Take a look at http://doc.qt.io/qt-5/qtest-tutorial.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          V 1 Reply Last reply
          0
          • V Violet Giraffe

            @jsulm
            Feature tests, I suppose. Or unit tests. There doesn't seem to be much difference in this context. Even when I'm unit-testing a single class or even single method, it still may require a lot of dependencies that I'm not keen on duplicating in the test.pro file (but I don't see any other way).

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Violet-Giraffe said in How to test the code from application (as opposed to library)?:

            Even when I'm unit-testing a single class or even single method, it still may require a lot of dependencies

            You can mock the dependencies.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @Violet-Giraffe For such tests you do not need your executable. Instead you create test executables where you include parts of your source code which you want to test. Take a look at http://doc.qt.io/qt-5/qtest-tutorial.html

              V Offline
              V Offline
              Violet Giraffe
              wrote on last edited by Violet Giraffe
              #6

              @jsulm said in How to test the code from application (as opposed to library)?:

              Instead you create test executables where you include parts of your source code which you want to test.

              I know. And I've seen the tutorial but it fails to address any real-life problems, the example is too artificially simple.

              So you suggest including the .cpp and .h files being tested - however many of them - directly into the test.pro?
              An interesting idea about mocking, thanks.

              jsulmJ 1 Reply Last reply
              0
              • V Violet Giraffe

                @jsulm said in How to test the code from application (as opposed to library)?:

                Instead you create test executables where you include parts of your source code which you want to test.

                I know. And I've seen the tutorial but it fails to address any real-life problems, the example is too artificially simple.

                So you suggest including the .cpp and .h files being tested - however many of them - directly into the test.pro?
                An interesting idea about mocking, thanks.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Violet-Giraffe Yes, you add the source files which you want to test and mock as many dependencies as possible.
                It is a good idea to do TDD - Test Driven Development. First write the tests which fails, then implement the actual functionality until the tests pass. This way you write code which can be tested more easily. Writing first the code and then the tests can be challanging.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                V 1 Reply Last reply
                3
                • jsulmJ jsulm

                  @Violet-Giraffe Yes, you add the source files which you want to test and mock as many dependencies as possible.
                  It is a good idea to do TDD - Test Driven Development. First write the tests which fails, then implement the actual functionality until the tests pass. This way you write code which can be tested more easily. Writing first the code and then the tests can be challanging.

                  V Offline
                  V Offline
                  Violet Giraffe
                  wrote on last edited by
                  #8

                  @jsulm
                  Thank you.

                  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