小编Gin*_*uni的帖子

如何正确调用 Assert::ExpectException?

我正在使用 Microsoft 的 CppUnitTestFramework 编写一些单元测试。

我想测试一下,我调用的方法是否抛出了正确的异常。我的代码是:

TEST_METHOD(test_for_correct_exception_by_input_with_whitespaces)
{
            std::string input{ "meet me at the corner" };
            Assert::ExpectException<std::invalid_argument>(AutokeyCipher::encrypt(input, primer));              
}
Run Code Online (Sandbox Code Playgroud)

在下面的链接中,我写了类似于上一个答案的电话:

C++/CX 中的函数指针

编译它时,我收到C2064错误:术语不计算为采用 0 个参数的函数

为什么这不起作用?

c++ unit-testing exception assertion microsoft-cpp-unit-test

5
推荐指数
1
解决办法
2802
查看次数