我正在嘗試創建運行測試所需的字符串數組。我就是這麼做的。在googletest框架中的for循環中運行EXPECT_THROWD
TEST(ParseTest, UnknownType) {
String test_strings[] = {
String("X 1024\n"),
String("AB 1024\n")
};
int test_strings_size = sizeof(test_strings)/sizeof(test_strings[0]);
for (int idx = 0; idx < test_strings_size; idx++) {
Transaction transaction;
String transaction_type = test_strings[idx];
EXPECT_THROW(transaction.parse(transaction_type), ParseError);
}
}
但是,當我在谷歌測試框架運行它,我得到以下錯誤:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from ParseTest
[ RUN ] ParseTest.UnknownRequestType
tests/transaction.cpp:20: Failure
Expected: transaction.parse(transaction_type) throws an exception of type ParseError.
Actual: it throws nothing.
[ FAILED ] ParseTest.UnknownRequestType (0 ms)
[----------] 1 test from ParseTest (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] ParseTest.UnknownRequestType
1 FAILED TEST
當這應該實際運行兩個測試用例,它抱怨的只有一個。我錯過了什麼嗎?