mardi 21 février 2017

Visual Studio C++ testing "name must be a namespace name" error

Here is what I did:

I first created a Win32ConsoleApplication

Here is the code in it:

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello World!" << endl;

    system("pause");
    return 0;
}

Then I add a Native Unit Test Project

In the unit test solution, I right click on the References tab, and then add by ConsoleApplication2 (name of project) reference.

Then I go to the unittest.cpp and this is what I see:

#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest8
{       
    TEST_CLASS(UnitTest1)
    {
    public:

        TEST_METHOD(TestMethod1)
        {
            // TODO: Your test code here
        }

    };
}

At the very top I add my own namespace, like this:

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ConsoleApplication2;

but then it's an error saying name must be a namespace name. Why is this? What did I do wrong?

Aucun commentaire:

Enregistrer un commentaire