为什么我的C ++ / CX单元测试不会失败? [英] Why my C++/CX unit-test does not fail?

查看:297
本文介绍了为什么我的C ++ / CX单元测试不会失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS 2012 C ++ / CX中有以下Windows Store / Metro Style测试方法



这一个成功,这是确定

  TEST_METHOD(TestMethod)
{
bool passed = false;
concurrency :: event finished;
finished.reset();
auto testTask = concurrency :: create_task([& finished,& passed]()
{
passed = true;
finished.set();
});
finished.wait(100000);
Assert :: IsTrue(passed);
}

这一个失败,也可以:

  TEST_METHOD(TestMethod)
{
bool passed = true;
concurrency :: event finished;
finished.reset();
auto testTask = concurrency :: create_task([& finished,& passed]()
{
passed = false;
finished.set();
});
finished.wait(100000);
Assert :: IsTrue(passed);
}

但是由于某种原因,此测试不会失败:

  TEST_METHOD(FailedTest)
{
concurrency :: event finished;
finished.reset();
auto testTask = concurrency :: create_task([& finished]()
{
Assert :: IsTrue(false);
finished.set();
});
finished.wait(100000);
}

我做错了什么?


$ b作为一个附注,一个可能的解决方法是将所有的测试结果放在变量中,并在 finished.wait(100000); ,但我仍然想知道我的工作是否真的有问题。

解决方案

测试失败。如果您打开测试输出窗口(查看 - >输出,然后在显示的输出,选择测试),您应该看到以下内容:


活动测试运行中止,因为执行过程意外退出。要进一步调查,请在计算机级别或进程vstest.executionengine.appcontainer.x86.exe启用本地崩溃转储。请访问更多详细信息: http://go.microsoft.com/fwlink/?linkid=232477&hl=zh_CN


在测试浏览器中,测试应显示为灰色,完成。不幸的是,由于测试运行完全失败,如果测试在过去的任何时间通过,测试仍显示在通过的测试组中,并且在其旁边仍有一个绿色复选标记。



我建议您在 Microsoft Connect 关于在这种情况下测试资源管理器中的混乱UI(如果您打开一个错误,请张贴该链接作为对此答案的评论或在你的问题,所以其他人可以找到它)。


I have the following "Windows Store/Metro Style" test methods in VS 2012 C++/CX

This one succeeds, which is ok

TEST_METHOD(TestMethod)
{
    bool passed = false;
    concurrency::event finished;
    finished.reset();                                   
    auto testTask = concurrency::create_task( [&finished, &passed]()
    {   
        passed = true;
        finished.set();
    }); 
    finished.wait(100000);
    Assert::IsTrue(passed);
}

This one fails, which is also ok:

TEST_METHOD(TestMethod)
{
    bool passed = true;
    concurrency::event finished;
    finished.reset();                                   
    auto testTask = concurrency::create_task( [&finished, &passed]()
    {   
        passed = false;
        finished.set();
    }); 
    finished.wait(100000);
    Assert::IsTrue(passed);
}

But for some reason, this test does not fail:

TEST_METHOD(FailedTest)
{
    concurrency::event finished;
    finished.reset();                                   
    auto testTask = concurrency::create_task( [&finished]()
    {   
        Assert::IsTrue(false);
        finished.set();
    });
    finished.wait(100000);          
}

Am I doing something wrong?

As a side note, a possible work-around could be to put all the results of my tests in variables and "test" them all after finished.wait(100000);, but I still would like to know if there is something actually wrong with what I am doing.

解决方案

The test does fail. If you open the Tests Output window (View -> Output, then under Show output from, select Tests), you should see the following:

The active Test Run was aborted because the execution process exited unexpectedly. To investigate further, enable local crash dumps either at the machine level or for process vstest.executionengine.appcontainer.x86.exe. Go to more details: http://go.microsoft.com/fwlink/?linkid=232477

In the Test Explorer, the test should appear grayed out because the test failed to run to completion. Unfortunately, because the test run fails completely, if the test had at any time in the past passed, the test still appears in the Passed Tests group and still has a green check mark next to it. Rely on the grayed-out name as an indication that the test did not run to completion.

I would recommend opening a bug on Microsoft Connect concerning the confusing UI in the Test Explorer in this scenario (if you open a bug, please post the link either as a comment to this answer or in your question, so others can find it).

这篇关于为什么我的C ++ / CX单元测试不会失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆