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. Console immediately closes when trying to run a unit test (Qt 5.12.2)
QtWS25 Last Chance

Console immediately closes when trying to run a unit test (Qt 5.12.2)

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5.12.2unit-testingtests
4 Posts 2 Posters 631 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.
  • F Offline
    F Offline
    feistykittykat
    wrote on 10 Aug 2019, 16:42 last edited by
    #1

    Hello all, new here, but not new to QT. I am however new to unit testing. I've been following through the unit test example, which makes things seem like they should be more straightforward than they actually are. I'm trying to use MSVC 2017 to generate and run a solution to my unit test project. However, the console only stays open for a brief instant before closing when I run my test project executable, so something is awry.

    The code I'm trying to run is:

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Includes
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    #include <QtTest/QtTest>
    //#include <QString>
    //#include <QObject>
    //#include <QUuid>
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Tests
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    class TestQString : public QObject
    {
        Q_OBJECT
    
    private slots:
        void toUpper();
    };
    
    void TestQString::toUpper()
    {
        QString str = "Hello";
        QCOMPARE(str.toUpper(), QString("HELLO"));
    }
    
    QTEST_MAIN(TestQString)
    #include "test_myFileName.moc"
    
    

    To generate the .pro file for the unit tests, I ran the following batch file:

    REM Build with visual studio make and qmake
    C:\"Program Files (x86)"\"Microsoft Visual Studio"\2017\Community\VC\Auxiliary\Build\vcvarsall.bat x86 && cd C:\Users\me\Documents\Projects\my-project\tests\unit_tests && c:\Qt\5.12.2\msvc2017\bin\qmake -project "QT += testlib"
    

    Which generated the following project file:

    ######################################################################
    # Automatically generated by qmake (3.1) Fri Aug 9 22:26:32 2019
    ######################################################################
    
    QT += testlib
    TEMPLATE = app
    TARGET = unit_tests
    INCLUDEPATH += .
    
    # The following define makes your compiler warn you if you use any
    # feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    # Input
    SOURCES += test_myFileName.cpp
    
    

    Then, I ran the following batch script, which generated the actual visual studio project:

    REM Build with visual studio make and qmake
    C:\"Program Files (x86)"\"Microsoft Visual Studio"\2017\Community\VC\Auxiliary\Build\vcvarsall.bat x86 && cd C:\Users\me\Documents\Projects\my-project\tests\unit_tests && c:\Qt\5.12.2\msvc2017\bin\qmake -r -tp vc
    PAUSE
    

    Then, I build this project in visual studio, which makes me sad, for two reasons. The first is the problem that I mentioned in my title. The second is that to even get this far, I needed to include the Qt5Core, Qt5Gui, Qt5Test, and Qt5Widgets dlls in the same folder as my executable. Historically, the qmake and vcvarsall.bat build approach that I've been taking hasn't made it necessary to manually include dlls for my other Qt projects, so I'm not sure why this is happening.

    Anyway, I've spent many hours just trying to get a working unit test up and running, and I'm pretty bummed out. Any suggestions, folks?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Aug 2019, 19:22 last edited by
      #2

      Hi and welcome to devnet,

      Are you using Visual Studio ?
      If so, there's an AddIn that you can use that will help you manage Qt project.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply 11 Aug 2019, 01:33
      0
      • S SGaist
        10 Aug 2019, 19:22

        Hi and welcome to devnet,

        Are you using Visual Studio ?
        If so, there's an AddIn that you can use that will help you manage Qt project.

        F Offline
        F Offline
        feistykittykat
        wrote on 11 Aug 2019, 01:33 last edited by
        #3

        @sgaist Yes, I mentioned that I am using visual studio 2017. I have the add-in installed, I'm not sure how that is supposed to help me with this very specific issue.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 11 Aug 2019, 20:05 last edited by
          #4

          My question wasn't about the compiler but the IDE since you could be using Qt Creator to develop your unit test.

          That's what I would suggest to test, to see if you obtain there the unit test you want.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          10 Aug 2019, 16:42

          • Login

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