+-

ASSERT_TRUE和ASSERT_FALSE都不会在带有错误的LibraryTest类中编译.
error C2664:
‘std::basic_string<_Elem,_Traits,_Alloc>::basic_string(const
std::basic_string<_Elem,_Traits,_Alloc> &)’ : cannot convert parameter
1 from ‘void’ to ‘const std::basic_string<_Elem,_Traits,_Alloc> &’
它起作用,因为在我使用的任何TEST_F中.
但是EXPECT_FALSE在LibraryTest类和TEST_F方法中编译都很好.
如何在TEST_F使用的方法中使用ASSERT?
class LibraryTest : public ::testing::Test
{
public:
string create_library(string libName)
{
string libPath = setup_library_file(libName);
LibraryBrowser::reload_models();
ASSERT_FALSE(library_exists_at_path(libPath));
new_library(libName, libPath);
ASSERT_TRUE(library_exists_at_path(libPath));
EXPECT_FALSE(library_exists_at_path(libPath));
return libPath;
}
};
TEST_F(LibraryTest, libraries_changed)
{
string libName = "1xEVTestLibrary";
string libPath = create_library(libName);
}
最佳答案
使用任何gtest断言的函数需要返回void.在您的情况下,您可以改变您的功能:
void create_library(const string &libName, string &libPath) {
libPath = ...
ASSERT_FALSE(...)
}
并像这样使用它:
TEST_F(LibraryTest, libraries_changed) {
string libName = "foo";
string libPath;
create_library(libName, libPath);
}
点击查看更多相关文章
转载注明原文:c – 为什么google测试ASSERT_FALSE在方法中不起作用,但EXPECT_FALSE起作用 - 乐贴网