Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. AutoTest / QtTest: Any experience here?
QtWS25 Last Chance

AutoTest / QtTest: Any experience here?

Scheduled Pinned Locked Moved Solved C++ Gurus
c++ qtunit testsquick2project files
5 Posts 2 Posters 2.3k 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.
  • 6 Offline
    6 Offline
    6thC
    wrote on 6 Jul 2017, 03:53 last edited by
    #1

    Really looking for a good guide how to use QtTest.
    How do I use my orignal quick2 application code (start with c++ code) from within the unit test application?

    I have a "Qt Quick 2 Controls Application" project and just now I've created a Auto Test Project using QtTest.
    I opened my non-test project so the are both at top level in projects and in my test project under Project, Dependencies I've selected my application project.

    This is all guesswork and the only test material I seem to find is just for standalone tests of math logic... well that's great if my entire project was to release a test project only... I have to ship a real working project.

    I cannot figure out how to reference my application classes? Just pretty lost and using lots of time. Also using a lot of time now I've got quite a bit going on... I'd like to really put my code through it's paces, logic tests first and maybe even performance tests/metrics. Help?

    J 1 Reply Last reply 6 Jul 2017, 04:53
    0
    • 6 6thC
      6 Jul 2017, 03:53

      Really looking for a good guide how to use QtTest.
      How do I use my orignal quick2 application code (start with c++ code) from within the unit test application?

      I have a "Qt Quick 2 Controls Application" project and just now I've created a Auto Test Project using QtTest.
      I opened my non-test project so the are both at top level in projects and in my test project under Project, Dependencies I've selected my application project.

      This is all guesswork and the only test material I seem to find is just for standalone tests of math logic... well that's great if my entire project was to release a test project only... I have to ship a real working project.

      I cannot figure out how to reference my application classes? Just pretty lost and using lots of time. Also using a lot of time now I've got quite a bit going on... I'd like to really put my code through it's paces, logic tests first and maybe even performance tests/metrics. Help?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 6 Jul 2017, 04:53 last edited by
      #2

      @6thC Usually in unit tests you just reference the source code files you want to test (in test PRO file):

      SOURCES += ../src/my_source_file.cpp
      HEADERS += ../src/my_source_file.h
      

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

      1 Reply Last reply
      0
      • 6 Offline
        6 Offline
        6thC
        wrote on 6 Jul 2017, 05:07 last edited by
        #3

        Hey, thanks. So doing this your way is really just referencing the actual source code / physical file from my real project hey? I was kinda hoping not to have to move everything into a library for this, this feels like good enough for me to get started at least writing and executing some tests... thanks.

        I also just found this: https://www.youtube.com/watch?v=nXokfmz7j18 - which demonstrated moving existing code into a library and using that from both projects.

        I think I'll start with yours, ta. I didn't realize I could just navigate down and up again and it all be ok. But that relationship with my app and testapp is exactly what I do want where I operate the tests on the current code. Thanks again.

        J 1 Reply Last reply 6 Jul 2017, 06:32
        0
        • 6 6thC
          6 Jul 2017, 05:07

          Hey, thanks. So doing this your way is really just referencing the actual source code / physical file from my real project hey? I was kinda hoping not to have to move everything into a library for this, this feels like good enough for me to get started at least writing and executing some tests... thanks.

          I also just found this: https://www.youtube.com/watch?v=nXokfmz7j18 - which demonstrated moving existing code into a library and using that from both projects.

          I think I'll start with yours, ta. I didn't realize I could just navigate down and up again and it all be ok. But that relationship with my app and testapp is exactly what I do want where I operate the tests on the current code. Thanks again.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 6 Jul 2017, 06:32 last edited by
          #4

          @6thC said in AutoTest / QtTest: Any experience here?:

          move everything into a library

          Why do you think you need to move everything into a library?!
          There is no need for a library.
          You just use your source code files in your test projects.
          Unit tests usually just include parts of the code files which are tested.
          Lets say you want to write a unit test for file_1.cpp and file_2.cpp which are part of your exe project. Then just create a unit test project and reference those files there - they will be compiled into the unit test executable.

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

          1 Reply Last reply
          0
          • 6 Offline
            6 Offline
            6thC
            wrote on 6 Jul 2017, 07:31 last edited by
            #5

            I was just mentioning that's how the video demonstrated.

            Thanks to you I have the files in my test project and they are the files from my actual app, now
            compiling seems to be the issue.

            I had a couple things to do to get it build able again but now I can at least compile my c++ classes. I have one test with one of my objects now so thanks.

            1 Reply Last reply
            0

            4/5

            6 Jul 2017, 06:32

            • Login

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