【发布时间】:2011-01-27 16:12:10
【问题描述】:
如何将参数传递给我的测试套件?
gtest --number-of-input=5
我有以下主要的 gtest 代码。并且--number-of-input=5 应该被传递给 InitGoogleTest()。
#include <iostream>
#include <gtest/gtest.h>
int main(int argc, char **argv) {
std::cout << "Running main() from gtest_main.cc\n";
::testing::GTEST_FLAG(output) = "xml:hello.xml";
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
我不知道如何将我的参数传递给测试套件/用例如下?
class TestTwo : public QuickTest {
protected:
virtual void SetUp() {
QuickTest::SetUp();
square = new Square(10);
circle = new Circle(10);
}
virtual void TearDown() {
delete square;
delete circle;
QuickTest::TearDown();
}
Square* square;
Circle* circle;
};
// Now, let's write tests using the QueueTest fixture.
// Tests the default constructor.
TEST_F(TestOne, DefaultConstructor) {
EXPECT_EQ(100.0, square->area());
}
TEST_F(TestOne, DefaultDestructor) {
EXPECT_EQ(1,1);
}
TEST_F(TestOne, VHDL_EMIT_Passthrough) {
EXPECT_EQ(1,1);
}
TEST_F(TestOne, VHDL_BUILD_Passthrough) {
EXPECT_EQ(1,1);
}
添加
我修改了 main 方法以在 InitGoogleTest() 之后显示 argv[i]。
int main(int argc, char **argv) {
std::cout << "Running main() from gtest_main.cc\n";
::testing::GTEST_FLAG(output) = "xml:hello.xml";
testing::InitGoogleTest(&argc, argv);
for (int i = 0; i < argc; i++) {
cout << i << ":" << argv[i] << endl;
}
这是给 gtest 的参数:./s --number-of-input=5 --gtest_filter=Test_Cases1*。
这是结果:
Running main() from gtest_main.cc
0:./s
1:--number-of-input=5
Note: Google Test filter = Test_Cases1*
[==========] Running 0 tests from 0 test cases.
[==========] 0 tests from 0 test cases ran. (0 ms total)
[ PASSED ] 0 tests.
gtest 过滤掉名称不为Test_Cases1 的测试,并显示除以gtest 开头的参数以外的正确参数。
【问题讨论】:
标签: c++ unit-testing googletest