简体   繁体   English

无法在CppUnitTestFramework(VS2013)中运行测试

[英]Can't run tests in CppUnitTestFramework (VS2013)

On a separate perforce stream from the rest of my team, I can't run CppUnitTestFramework tests on a project, while the rest of the streams run the tests just fine. 在与团队其余人员分开的perforce流上,我无法在项目上运行CppUnitTestFramework测试,而其余流则可以很好地运行测试。

Here's a code snippet: 这是一个代码片段:

TEST_CLASS(MyClass)
{
    BEGIN_TEST_CLASS_ATTRIBUTE()
        TEST_CLASS_ATTRIBUTE(L"Type", L"Native C++ Unit Tests")
        TEST_CLASS_ATTRIBUTE(L"TestClass", L"MyClass")
        END_TEST_CLASS_ATTRIBUTE()

public:

    TEST_METHOD(canFooTheBar)
    {
        ...
        Assert::IsTrue(foo());
    }
...
}

Here is the error I get when trying to run a test: 这是尝试运行测试时遇到的错误:

------ Discover test started ------
Object reference not set to an instance of an object.
========== Discover test finished: 0 found (0:00:00.5129487) ==========
No tests found to run.

There are no diffs between the .sln, or any of the relevant .vcxproj files between the different streams. .sln之间或不同流之间的任何相关.vcxproj文件之间没有差异。

A possible reason is that you have a test class that has no tests (in the same project). 一个可能的原因是您拥有一个没有测试的测试类(在同一项目中)。

Removing such class may solve the problem. 删除此类可以解决问题。

The problem is reproduced if I add the following class to the project: 如果将以下类添加到项目中,则会重现该问题:

TEST_CLASS(MyEmptyClass)
{
    BEGIN_TEST_CLASS_ATTRIBUTE()
        TEST_CLASS_ATTRIBUTE(L"Type", L"Native C++ Unit Tests")
        TEST_CLASS_ATTRIBUTE(L"TestClass", L"MyEmptyClass")
        END_TEST_CLASS_ATTRIBUTE()

public:
    //no tests
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM