Darien Pardinas
Darien Pardinas

Reputation: 6186

How to setup unit testing in Qt - Visual Studio 2013 project

I want to be able to use the Visual Studio unit testing framework to test Qt libraries created with the QT Visual Studio add-in. Currently there is no out-of-the-box way to create a native C++ Unit Test with Qt Meta Object Compiler support. The need for this is if you want to unit-test classes that uses the Q_OBJECT macro.

Upvotes: 1

Views: 2170

Answers (1)

Darien Pardinas
Darien Pardinas

Reputation: 6186

So this worked very well for me:

I created a "Qt Library" project using the template provided with the Qt Visual Studio add-in.

Then I did the following modifications on the properties of the project:

  • Added $(VCInstallDir)UnitTest\include to the "Additional Include Directories"

  • Added $(VCInstallDir)UnitTest\lib to the "Additional Library Directories".

  • Added my tests like this in a .cpp file:

    #include "CppUnitTest.h"
    using namespace Microsoft::VisualStudio::CppUnitTestFramework;
    namespace MyUnitTests
    {       
        TEST_CLASS(MyTestClass)
        {
        public:
    
            TEST_METHOD(MyTestFunction)
            {
                // TODO: Your test code here
    
            }
    
        };
    }
    

Upvotes: 6

Related Questions