如何将参数传递给我的测试套件?
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()
.
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
。